Load and unload external swf
I'm simply trying to load external .swfs at different stages
within my flash movie, as selected by the user.
The problem i'm having is that once a .swf is loaded it stays
loaded. I would like it to disappear when the user navigates to a
different part of the main flash movie.
Here's what i'm using:
_root.createEmptyMovieClip("container",1);
container.loadMovie("EXTERNALMOVIE.swf");
container._x = container._y = 50 ;
Help much appreciated!
Obviously this went unanswered due to the easy way of using the loader component.
So simple !
RDemtl
Similar Messages
-
Problem with loading and unloading external swfs
Hello Forum,
I'm pretty new to as3, and it's giving me a great challenge. I have a large number of captivate files that I want to play inside a simple container built in CS5.5... but switching back and forth between all the movies hogs the memory like crazy, so I need something to clean it up. All code is in a single frame on the main timeline. First, I create the loader:
var FlashLoader:Loader = new Loader();
var flashUrl:URLRequest = new URLRequest("placeholder.swf");
FlashLoader.load(flashUrl);
addChild(FlashLoader);
The actual movies are located via an XML... but as I said the memory problem is huge, so I tried to build something to get rid of that. Ideally, I want the loader to clean up everything and start life anew with a single mouse click, like so:
function _mouseClickHandler2(event:MouseEvent):void {
FlashLoader.unloadAndStop();
FlashLoader.parent.removeChild(FlashLoader);
FlashLoader = null;
var flashUrl:URLRequest = new URLRequest(event.target.href);
var FlashLoader:Loader = new Loader();
addChild(FlashLoader);
FlashLoader.load(flashUrl);
FlashLoader.x = 120;
setChildIndex(FlashLoader,0);
trace(FlashLoader.parent.numChildren);
// System.gc();
// System.gc();
// try {
// new LocalConnection .connect('gc');
// new LocalConnection .connect('gc');
// } catch (e: * ) {
// trace(getMemory ());
//trace(event.target.href);
//trace(event.target.text);
Upon clicking on the menu (and thus switching movies), I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Treeview_working_fla::MainTimeline/_mouseClickHandler2()
And this doesn't make sense to me. The FlashLoader is given a placeholder swf at the beginning, so why would the FlashLoader inside the function be recognized as having a null object reference?
Thanks in advanceIn my quest to tackle this problem, I've decided to try and isolate the problem, and have made a simple "click to load, click to unload" when I stumbled upon a curious problem. The movie loads fine, and the UNLOAD function upon mouseclick also works perfectly. However, upon clicking again to activate RELOAD, it gives the error "No active security context" and refuses to load the same exact swf with the same exact path that successfully loaded the first time!
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
var FlashLoader:Loader = new Loader();
var flashUrl:URLRequest = new URLRequest("folder/subfolder/movie.swf");
FlashLoader.x = 120;
FlashLoader.load(flashUrl);
stage.addChild(FlashLoader);
stage.addEventListener(MouseEvent.CLICK, UNLOAD);
function UNLOAD(event:MouseEvent) {
flashUrl = null;
stage.removeChild(FlashLoader);
FlashLoader.unloadAndStop();
stage.removeEventListener(MouseEvent.CLICK, UNLOAD);
stage.addEventListener(MouseEvent.CLICK, RELOAD);
function RELOAD(event:MouseEvent) {
var FlashLoader:Loader = new Loader();
var flashUrl:URLRequest = new URLRequest("folder/subfolder/movie.swf");
FlashLoader.x = 120;
FlashLoader.load(flashUrl);
stage.addChild(FlashLoader);
stage.removeEventListener(MouseEvent.CLICK, RELOAD);
stage.addEventListener(MouseEvent.CLICK, UNLOAD); -
I know that the question sounds confusing. I am new to AS3 but a little dangerous with it.
The project
I'm putting together a website tour with has a main .fla with navigation buttons. The navigation buttons load external .swfs using X and Y properties. Every external .swf houses a scrubber bar, play pause buttons which calls to a movie clip which houses the animation.
The problem:
Everything was working great, until someone mentioned "Hey, what if at the end of each loaded external .swf, a button appears that says "go to next section".
So basically we are trying to give the user another way to get to the next section in the left hand navigation once the animation ends, in addition to being able to click in the left hand navigation for the next section. It's kind of like when a youTube video ends and it displays a button to go to the next movie that's in line, but you can also do it in the thumnail navigation as well.
Ok, let's try it. Well, after many nights, searching the web and trying everything I am waving the white flag. I went through the lynda.com book over and over but I get an error message when I add code related to the parent timeline. I can actually get the next section to load on top of the previously loaded .swf, but it's buggy and I think the previous section is showing through underneath. Plus the scrubber isn't really working right. Since every .swf has a scrubber to control it, shouldn't it just load on top of the previous .swf? Do I need to add coding related to the parent timeline?
I don't know if I should paste my code here, I have a sample .fla too. Help is so greatly appreciated!!!! If this can work, I think it would be very useful for anyone else doing something like this - I would definitely share any knowledge gained!
Thanks.
JenIf you want to utilize that code as a starting point (hopefully you understand what it does, and that the code actually works), then you need to modify it such that the array at the start has your filenames instead of the three it now shows, and the three buttons it uses are changed to the next and previous buttons you intend to use. Here are the functions you need to make adjustments to...
function onCompletePreloading():void {
_loadedSWFs = 0;
contentContainer.addChild(_swfClipsArr[_loadedSWFs]);
next_btn.addEventListener(MouseEvent.CLICK, setContent);
prev_btn.addEventListener(MouseEvent.CLICK, setContent);
function setContent(event:MouseEvent):void {
var _swfToAdd:MovieClip;
if(event.currentTarget.name == "next_btn") {
_loadedSWFs += 1;
if(_loadedSWFs == _swfClipsArr.length){
_loadedSWFs = 0;
} else if(event.currentTarget.name == "prev_btn"){
_loadedSWFs -= 1;
if(_loadedSWFs == -1){
_loadedSWFs = _swfClipsArr.length-1;
_swfToAdd = _swfClipsArr[_loadedSWFs];
contentContainer.removeChildAt(contentContainer.numChildren-1);
contentContainer.addChild(_swfToAdd);
trace(_swfToAdd.customID); -
How to load and unload same SWF with different xmlFilePath?
I have a slideshow on my homepage and try to load and unload same instance with different xmlFilePath based on language on the same page.
var flashvars = {
xmlFilePath: escape("http://www.bodto.com.tr/kik.aspx"),
xmlFileType: "OPML",
lang: swfobject.getQueryParamValue("lang")
//initialURL: escape(document.location)
var params = {
bgcolor: "#000000",
allowfullscreen: "true",
wmode:"transparent",
allowScriptAccess: "always"
var attributes = {}
swfobject.embedSWF("/swf/slideshowpro.swf", "flashcontent", "550", "400", "10.0.0", false, flashvars, params, attributes);
Actionscript3
var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
my_ssp.xmlFilePath = langPath;
var fileType = root.LoaderInfo.parameters["xmlFileType"];
my_ssp.xmlFileType = fileType;
Based on above informations, how could I achieve it?Suddenly that code in the following gives me some error
var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
my_ssp.xmlFilePath = langPath;
var fileType = root.LoaderInfo.parameters["xmlFileType"];
my_ssp.xmlFileType = fileType;
Access of possibly undefined property LoaderInfo through a reference with static type flash.display:DisplayObject.
The only code snippet works is
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (var param in paramObj) {
if (param == "xmlFilePath") {
my_ssp.xmlFilePath = paramObj[param];
if (param == "xmlFileType") {
my_ssp.xmlFileType = paramObj[param]; -
Transition_Manager and unloading external swf problems
Hi there
I´m having a few problems with my project which i although it work it has some unpleasant bugs that i´m trying to solve for days.
When i load external swf´s they show up on top of the Menu button.Maybe because the button i´m pressing is inside the same movieclip as the Menu.
Explaining better here´s a little diagram of my site:
con2 MC (Instance of Menu) ---> cont3 MC (Instance of subMenu) and mainButton MC (Instance of Main)
Here´s the general code which is inside the Painel.as
package {
import com.greensock.TweenLite;
import com.greensock.TweenMax;
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.*;
import flash.events.*;
import flash.display.MovieClip;
import fl.transitions.*;
import fl.transitions.easing.*;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
public class Painel3 extends MovieClip
private var inFocus:MovieClip;
public function Painel3():void
setupClips();
addEventListener(Event.ENTER_FRAME, loop);
private function setupClips():void
con2.mainButton.addEventListener(MouseEvent.ROLL_OVER, onOver);
con2.mainButton.addEventListener(MouseEvent.ROLL_OUT, onOut);
con2.mainButton.addEventListener(MouseEvent.CLICK, onClick);
var len:int = con2.cont3.numChildren;
for(var i:int=0; i<len; i++)
var mc:MovieClip = MovieClip(con2.cont3.getChildAt(i));
mc.buttonMode = true;
mc.loc = [mc.x, mc.y];
mc.addEventListener(MouseEvent.CLICK, onClick);
con2.cont3.visible = false;
private function onOver(e:MouseEvent):void
private function onOut(e:MouseEvent):void
private function onClick(e:MouseEvent):void
con2.cont3.visible = true;
TransitionManager.start(con2.cont3, {type:Wipe, direction:Transition.IN, duration:1, easing:None.easeNone, startPoint:5} );
private function loop(e:Event):void
var distx:Number = mouseX / 1400;
var disty:Number = mouseY / 1400;
TweenLite.to(con2, 2, {
rotationY:(-70 +(145*distx)),
rotationX:(70 -(145*disty)),
ease:Expo.easeOut
And then inside the subMenu.as class for the movieclip subMenu i have the buttons that load the external swf´s:
package {
import com.greensock.TweenLite;
import com.greensock.TweenMax;
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.*;
import flash.events.*;
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import fl.transitions.*;
import fl.transitions.easing.*;
public class subMenu extends MovieClip {
public function subMenu() {
// constructor code
menu1.buttonMode = true;
menu2.buttonMode = true;
menu3.buttonMode = true;
menu4.buttonMode = true;
menu1.addEventListener(MouseEvent.CLICK,link1);
menu2.addEventListener(MouseEvent.CLICK,link2);
menu3.addEventListener(MouseEvent.CLICK,link3);
menu4.addEventListener(MouseEvent.CLICK,link4);
function link1(e:MouseEvent) {
function startLoad()
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("AugmentedReality_v1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
function onCompleteHandler(e:Event):void {
var swf:DisplayObject = e.target.content;
swf.x = -400;
swf.y = -300;
addChild(swf);
function onProgressHandler(mProgress:ProgressEvent)
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
startLoad();
function link2(e:MouseEvent) {
function startLoad()
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("Fotos.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
function onCompleteHandler(e:Event):void {
var swf:DisplayObject = e.target.content;
swf.x = -400;
swf.y = -300;
addChild(swf);
function onProgressHandler(mProgress:ProgressEvent)
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
startLoad();
function link3(e:MouseEvent) {
function link4(e:MouseEvent){
function startLoad()
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("Texto.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
function onCompleteHandler(e:Event):void {
var swf:DisplayObject = e.target.content;
swf.x = -400;
swf.y = -300;
addChild(swf);
function onProgressHandler(mProgress:ProgressEvent)
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
startLoad();
Like i said the swf´s show up on top of the Menu and i need it to dissapear.
Also i want to unload the swf currently in scene so that when i load another one they don´t pile on top of each other.
Pls help. ThanksOh btw, i´m having an error 1069 Property TransitionManager not found in subMenu and there is no default value
at fl.transitions::TransitionManager$/start()
at Painel3/onClick()
This doesn´t happen when i uncheck the Export for actionscript in the subMenu class but i can´t do that or else the buttons wont work. -
Loading and Unloading of swf files in SWF Loader
Hi all,
I have a doubt reg. SWF Loader.
I have created two mxml files A & B.
A. local.mxml
B. SwfSample.mxml
i have two labels and a button in A file and i have set values to those labels and have a method to handle the click event of the button. In B file i have loaded this A file and accessed the labels and methods using SystemManager Component and changed the values of the A file's label and accessed data from A file to B file.
Here comes the problem,
I have two buttons named LoadAgain and Unload
When i click the Unload button, the SWF Loader unloads its content by the method i handled for the Unload button, after that i have clicked on the LoadAgain button to load the same content of A's mxml to the SWF Loader, it loads succesfully,but i was not able to access its Label or Method from the B mxml. Please help me to solve the issue.
local.mxml
<?xml version="1.0" encoding="utf-8"?><mx:Application
xmlns:mx=http://www.adobe.com/2006/mxml layout="absolute">
<mx:Script>
<![CDATA[
Bindable]
public var varOne:String = "This is a public variable";
public function setVarOne(newText:String):void
varOne = newText;
]]>
</mx:Script>
<mx:Label id="lblOne" text="I am here" x="28" y="88"/>
<mx:Label text="{varOne}" x="166" y="88"/>
<mx:Button label="Nested Button" click="setVarOne('Nested Button Pressed');" x="28" y="114"/>
SwfSample.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx=http://www.adobe.com/2006/mxml layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.SystemManager;
import mx.controls.Label;
Bindable]
public var loadedSM:SystemManager;
private function initNestedAppProps():void
loadedSM = SystemManager(myLoader.content);
public function updateLabel():void
lbl.text = loadedSM.application[
"lblOne"].text;
public function updateNestedLabels():void
loadedSM.application[
"lblOne"].text = "I was just updated" ;
loadedSM.application[
"varOne"] = "I was just updated";
public function updateNestedVarOne():void
local(loadedSM.application).setVarOne(
"Updated varOne");
public function unload():void
myLoader.content.loaderInfo.loader.unload();
public function loadAgain():void
myLoader.load(
"../bin-debug/local.swf");
]]>
</mx:Script>
<mx:Label id="lbl" x="72" y="47"/>
<mx:SWFLoader id="myLoader" width="438" source="../bin-debug/local.swf" creationComplete="initNestedAppProps();" y="73" height="238" x="72" alpha="1.0"/>
<mx:Button label="Update Label Control in Outer Application" click="updateLabel();" x="72" y="319"/>
<mx:Button label="Update Nested Controls" click="updateNestedLabels();" x="72" y="349"/>
<mx:Button label="Update Nested varOne" click="updateNestedVarOne();" x="72" y="379"/>
<mx:Button label="Unload" click="unload();" x="72" y="409"/>
<mx:Button label="Load Again" click="loadAgain();" x="72" y="439"/>
</mx:Application>
Thanks & regards,
Sathish.KcreationComplete only fires once when the SWFLoader is created. Therefore you never reset your variables to point to the new sub-app. On a slow network, creationComplete may fire before the sub-app loads. It is best to use the COMPLETE event.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui -
Fully loaded and rendered external SWF printing problem.
I have an application that loads external SWF files that I have not built and do not have the codebase for.
I need to know when these SWFs are fully loaded and have rendered themselves on the screen.
Even gone to the point of giving them 80 enter frame events before trying to print and they show up on the paper sporadically.
Does anyone know if there's some standard event coming from some object internal to SWFLoader that would let me know when the SWF is "running?"There is no way to know in the general case. If it had an animation of
birds flying around on it, when would be the right time to print it? -
AS3 Unloading external SWF piling up problem
I have two buttons on main SWF what loads and Unload two external SWFs back and forth.
Also one timer function is calling external Screen saver SWF and unload the existing one when no interaction found.
I am using unloadAndStop() function to unload the external SWFs.
But after loading and unloading external SWFs, I am facing piling up or stack overflow problem.
Any help will be highly appreciated.
Thanks
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.display.MovieClip;
import caurina.transitions.*;
import flash.utils.Timer;
import flash.events.*;
var myLoader_Map_1:Loader = new Loader();
var myLoader_Map_2:Loader = new Loader();
var myLoader_Screen_Saver:Loader = new Loader();
var Ss:Boolean = false;
var Maps:Boolean = true;
//--------------------Screen Saver---------------------------------
ScreenSaver();
function ScreenSaver():void{
var url:URLRequest = new URLRequest("screensaver.swf");
myLoader_Screen_Saver.load(url);
addChild(myLoader_Screen_Saver);
setChildIndex(myLoader_Screen_Saver, 1);
Maps = false;
Ss = true;
function ScreenSaver_Unload():void{
myLoader_Screen_Saver.unloadAndStop();
//--------------------Map Buttons---------------------------------
function MPstart():void{
Tweener.addTween(MC_Maps_Btns,{alpha:1, x:778.25, y:1070.65, time:1, delay:1, transition:"easeOutCubic"});
setChildIndex(MC_Maps_Btns, 2);
MC_Maps_Btns.Btn_Map_1.visible = true;
MC_Maps_Btns.Btn_Map_2.visible = true;
function MPclose():void{
Tweener.addTween(MC_Maps_Btns,{alpha:0, x:778.25, y:1179.85, time:1, transition:"easeOutCubic"});
//--------------------Map 1 ---------------------------------
MC_Maps_Btns.Btn_Map_1.addEventListener(MouseEvent.CLICK,OpenMap1);
function OpenMap1(e:MouseEvent):void{
var url:URLRequest = new URLRequest("Map_1.swf");
myLoader_Map_1.load(url);
myLoader_Map_1.alpha = 1;
addChild(myLoader_Map_1);
setChildIndex(myLoader_Map_1, 2);
myLoader_Map_2.unloadAndStop();
ScreenSaver_Unload();
Maps = true;
Ss = false;
MC_Maps_Btns.Btn_Map_1.visible = false;
MC_Maps_Btns.Btn_Map_2.visible = true;
//--------------------Map 1 ---------------------------------
MC_Maps_Btns.Btn_Map_2.addEventListener(MouseEvent.CLICK,OpenMap2);
function OpenMap2(e:MouseEvent):void {
var url:URLRequest = new URLRequest("Map_2.swf");
myLoader_Map_2.load(url);
myLoader_Map_2.alpha = 1;
addChild(myLoader_Map_2);
setChildIndex(myLoader_Map_2, 2);
myLoader_Map_1.unloadAndStop();
ScreenSaver_Unload();
Maps = true;
Ss = false;
MC_Maps_Btns.Btn_Map_2.visible = false;
MC_Maps_Btns.Btn_Map_1.visible = true;
//--------------------Timer ---------------------------------
var inactiveTime:int = 10000;
var t:Timer = new Timer(inactiveTime);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown1);
t.addEventListener(TimerEvent.TIMER, onTimer);
t.start();
function onMouseDown1(e:MouseEvent):void {
t.reset();
t.start();
trace("Interaction detected");
function onTimer(e:TimerEvent):void {
handleInactivity();
function handleInactivity():void {
trace('You\'re inactive.');
if (Maps == true){
myLoader_Map_1.unloadAndStop();
myLoader_Map_2.unloadAndStop();
else{
trace("No Maps");
if (Ss == false ){
ScreenSaver();
MPclose();
else{
trace("ScreenSaver already loaded");This is how I applied
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.display.MovieClip;
import caurina.transitions.*;
import flash.utils.Timer;
import flash.events.*;
var myLoader_Map_1:Loader = new Loader();
var myLoader_Map_2:Loader = new Loader();
var myLoader_Screen_Saver:Loader = new Loader();
var Ss:Boolean = false;
var Maps:Boolean = true;
//--------------------Screen Saver---------------------------------
function unloadAllF():void{
if(myLoader_Screen_Saver.content){
myLoader_Screen_Saver.unloadAndStop();
trace("ss unloaded");
if(myLoader_Map_1.content){
myLoader_Map_1.unloadAndStop();
trace("map_1 unloaded");
if(myLoader_Map_2.content){
myLoader_Map_2.unloadAndStop();
trace("map_2 unloaded");
//etc
ScreenSaver();
function ScreenSaver():void{
var url_ss:URLRequest = new URLRequest("screensaver.swf");
unloadAllF();
myLoader_Screen_Saver.load(url_ss);
addChild(myLoader_Screen_Saver);
setChildIndex(myLoader_Screen_Saver, 1);
Maps = false;
Ss = true;
function ScreenSaver_Unload():void{
myLoader_Screen_Saver.unloadAndStop();
//--------------------Map Buttons---------------------------------
function MPstart():void{
Tweener.addTween(MC_Maps_Btns,{alpha:1, x:778.25, y:1070.65, time:1, delay:1, transition:"easeOutCubic"});
setChildIndex(MC_Maps_Btns, 2);
MC_Maps_Btns.Btn_Map_1.visible = true;
MC_Maps_Btns.Btn_Map_2.visible = true;
function MPclose():void{
Tweener.addTween(MC_Maps_Btns,{alpha:0, x:778.25, y:1179.85, time:1, transition:"easeOutCubic"});
//--------------------Map 1 ---------------------------------
MC_Maps_Btns.Btn_Map_1.addEventListener(MouseEvent.CLICK,OpenMap1);
function OpenMap1(e:MouseEvent):void{
var url_map_1:URLRequest = new URLRequest("Map_1.swf");
unloadAllF();
myLoader_Map_1.load(url_map_1);
myLoader_Map_1.alpha = 1;
addChild(myLoader_Map_1);
setChildIndex(myLoader_Map_1, 2);
myLoader_Map_2.unloadAndStop();
ScreenSaver_Unload();
Maps = true;
Ss = false;
MC_Maps_Btns.Btn_Map_1.visible = false;
MC_Maps_Btns.Btn_Map_2.visible = true;
//--------------------Map 1 ---------------------------------
MC_Maps_Btns.Btn_Map_2.addEventListener(MouseEvent.CLICK,OpenMap2);
function OpenMap2(e:MouseEvent):void {
var url_map_2:URLRequest = new URLRequest("Map_2.swf");
unloadAllF();
myLoader_Map_2.load(url_map_2);
myLoader_Map_2.alpha = 1;
addChild(myLoader_Map_2);
setChildIndex(myLoader_Map_2, 2);
myLoader_Map_1.unloadAndStop();
ScreenSaver_Unload();
Maps = true;
Ss = false;
MC_Maps_Btns.Btn_Map_2.visible = false;
MC_Maps_Btns.Btn_Map_1.visible = true;
//--------------------Timer ---------------------------------
var inactiveTime:int = 10000;
var t:Timer = new Timer(inactiveTime);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown1);
t.addEventListener(TimerEvent.TIMER, onTimer);
t.start();
function onMouseDown1(e:MouseEvent):void {
t.reset();
t.start();
trace("Interaction detected");
function onTimer(e:TimerEvent):void {
handleInactivity();
function handleInactivity():void {
trace('You\'re inactive.');
if (Maps == true){
myLoader_Map_1.unloadAndStop();
myLoader_Map_2.unloadAndStop();
else{
trace("No Maps");
if (Ss == false ){
ScreenSaver();
MPclose();
else{
trace("ScreenSaver already loaded"); -
Hi,
I'm struggling to understand this, so I'm hoping someone can explain how to further enhance the functionality of my simple unload function, or maybe just point out some best practices in unloading external content.
The scenario is that I'm loading and unloading external swfs into my movie(many, many times over) In order to load my external content, I am doing the following:
Declare global loader:
var assetLdr:Loader = new Loader();
Load the content using this function:
function loadAsset(evt:String):void{
var assetName:String = evt;
if (assetName != null){
assetLdr = new Loader();
var assetURL:String = assetName;
var assetURLReq:URLRequest = new URLRequest(assetURL);
assetLdr.load(assetURLReq);
assetLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)
assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);
function loaded(event:Event):void {
var targetLoader:Loader = Loader(event.target.loader);
assetWindow.addChild(targetLoader);
Unload the content using this function:
function unloadAsset(evt:Loader) {
trace("UNLOADED!");
evt.unload();
Do the unload by calling the function via:
unloadAsset(assetLdr)
This all seems to work pretty well, but at the same time I am suspicious that the content is not truly unloaded, and some reminents of my previously loaded content is still consuming memory. Per my load and unload function, can anyone suggest any tips, tricks or pointers on what to add to my unload function to reallocate the consumed memory better than how I'm doing it right now, or how to make this function more efficient at clearing the memory?
Thanks,
~ChiplehSince you use a single variable for loader, from GC standpoint the only thing you can add is unloadAndStop().
Besides that, your code has several inefficiencies.
First, you add listeners AFTER you call load() method. Given asynchronous character of loading process, especially on the web, you should always call load() AFTER all the listeners are added, otherwise you subject yourself to unpredictable results and bud that are difficult to find.
Second, nested function are evil. Try to NEVER use nested functions. Nested functions may be easily the cause for memory management problems.
Third, your should strive to name variables in a manner that your code is readable. For whatever reason you name functions parameters evt although a better way to would be to name them to have something that is descriptive of a parameter.
And, please, when you post the code, indent it so that other people have easier time to go through it.
With that said, your code should look something like that:
function loadAsset(assetName:String):void{
if (assetName) {
assetLdr = new Loader();
assetLdr.contentLoaderInfo.addEventListener(Event.INIT , loaded);
assetLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, displayAssetLoaderProgress);
// load() method MUST BE CALLED AFTER listeners are added
assetLdr.load(new URLRequest(assetURL));
// function should be outside of other function.
function loaded(e:Event):void {
var targetLoader:Loader = Loader(event.target.loader);
assetWindow.addChild(targetLoader);
function unloadAsset(loader:Loader) {
trace("UNLOADED!");
loader.unload();
loader.unloadAndStop(); -
How to load and unload Multiple External SWF
hello there,
i need help to figuring out how to load and also unload(removing) multiple external SWF.
so here is what i;m trying to do,
i want to load multiple external SWF and play it on my main SWF now i hove no problem with just loading multiple SWF and placing it in the display list .The problem came up when i tried removing those loaded SWF from the display list ,The problem exist because i have no way to refer to what i have loaded and placed on the display list,
i used a single loader instance to load all that external swf,
i do know that we have to remove all the event listener related to the external SWF that we want to remove and for this purpose i have crated a function called destroy which the main objective for this function is to remove all event listener inside the swf and also isolating all variable so it would be eligible for garbage collecting, here is what the code look like:
// Create this in every object you use
public function destroy():void
// Remove event listeners
// Remove anything in the display list
// Clear the references to other objects, so it gets totally isolated
sorry it just a kind of pseudocode cause this function will customize with it's own property i did this just for the purpose of simplicity and easy understanding..,
so now back to main problem how should i solve this problem??
i tried used an arraf to save all the loaded swf
the array is just used to save the what the loader is loading but the adding to display method is using
movieClipActAsContainer.addChild(e.target.content); //the event is from the Event.COMPLETE
but i have a hard time using that arrya back and matching it to the one i got from the display list.
please do help me,
any suggestion would be greatly appreciated,
and if can pleas show me a source code or pseudocode of what you're suggesting to me cause my english is not so fluent yet,
thanks before.Hey EI,
I had done this kind of project recently and for loading and unloading different swfs. I had used loaders specific to that filename and for removing I had used a single movieclip instance name and on clicking that specific loader request name that needs to be removed will be requested from the specific function. As mentioned below
Loading SWF:
===============================
swfLoaderIndia.load(swfRequestIndia);//This will load the request
If you are inside a movieclip while requesting use below code
MovieClip(this.root).addChild(swfLoaderIndia);//This will load swf on stage
or else
Stage.addChild(swfLoaderIndia);
Unloading SWF
=====================================
If you are inside a movieclip while requesting use below code
MovieClip(this.root).removeChild(swfLoaderIndia);//This will unload swf on stage
or else
Stage.removeChild(swfLoaderIndia);
Above code will be in specific function which will be requested when the loading and unloading is required.
I hope this helps you in your project.
With Regards,
Sagar S. Ranpise -
Display/load and Unload SWF in flex
hi friends
i wnat to disply external SWF file into flex but without using SWFLOader(it's make lot's of problem) nad i also Embed that SWF
this is code
[Embed(source="1.swf")]
private var loadswf:Class;
private function load():void{
var symb:MovieClip = new loadswf() as MovieClip;
this.addChild(symb);
it's give me error....
TypeError: Error #1034: Type Coercion failed: cannot convert demos_loadswf@39ab3c1 to mx.core.IUIComponent.
please help to resolve this error or give me suggestion to simple Disply/Load and Unload Embed SWF file in flexthnx Flex harUI
i added UI componentes now my full code is like..
import mx.controls.Image;
import mx.controls.Alert;
[Embed(source = "1.swf")]
public var SWF:Class;
[Embed(source = "2.swf")]
public var SWF2:Class;
private var mc:MovieClip;
private var img:Image;
protected function checkBtn_clickHandler(event:MouseEvent):void
clear();
img = new Image();
img.width=Number("700");
img.height=Number("700");
mc = new MovieClip();
mc = MovieClip(new SWF());
img.source = mc;
vBox0.addChild(img);
protected function critcalBtn_clickHandler(event:MouseEvent):void
clear();
img = new Image();
img.width=Number("700");
img.height=Number("700");
mc = new MovieClip();
mc = MovieClip(new SWF2());
img.source = mc;
vBox0.addChild(img);
protected function clear():void
try{
if(mc!=null){
flash.media.SoundMixer.stopAll();
img.source="";
img.source=null;
mc=null;
vBox0.removeChild(DisplayObject(img));
vBox0.removeAllElements();
vBox0.removeAllChildren();
}catch(e:Error){
Alert.show(e + " ----::---- ");
<mx:Canvas id="vBox0" width="700" height="700" ></mx:Canvas>
<mx:HBox >
<mx:Button id="checkBtn" label="first" click="checkBtn_clickHandler(event)"/>
<mx:Button id="critcalBtn" label="second" click="critcalBtn_clickHandler(event)"/>
</mx:HBox>
now my error gone!!! but one problem is there when i unload my first SWF and load second SWF(on button click), my first SWF sound are still play in Background, i cn't unstand Y this will happen coz i already remove all object and child from my Canvas.
any help on this.... -
How to load and unload more than one external swf files in different frames?
I do not have much experience on Adobe Flash or Action Script 3, but I know the basics.
I am Arabic language teacher, and I design an application to teach Arabic, I just would like to learn how to load and unload more than one external swf files in different frames.
ThanksLook into using the Loader class to load the swf files. If you want to have it happen in different frames then you can put the code into the different frames.
-
I can't seem to remove / unload the external swf files e.g when the carousel.swf (portfolio) is displayed and I press the about button the about content is overlapping the carousel (portfolio) . How can I remove / unload an external swf file from the main flash file and load a new swf file, while at the same time removing garbage collection from memory?
This is the error message(s) I am receiving: "TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/removeChild()
at index_fla::MainTimeline/Down3()"
import nl.demonsters.debugger.MonsterDebugger;
var d:MonsterDebugger=new MonsterDebugger(this);
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
// loader is the loader for portfolio page swf
var loader:Loader;
var loader2:Loader;
var loader3:Loader;
var loader1:Loader;
// resize content
function resizeHandler(event:Event):void {
// resizes portfolio page to center
loader.x = (stage.stageWidth - loader.width) * .5;
loader.y = (stage.stageHeight - loader.height) * .5;
// resizes about page to center
loader3.x = (stage.stageWidth - 482) * .5 - 260;
loader3.y = (stage.stageHeight - 492) * .5 - 140;
/*loader2.x = (stage.stageWidth - 658.65) * .5;
loader2.y = (stage.stageHeight - 551.45) * .5;*/
addEventListener(Event.ENTER_FRAME, onEnterFrame,false, 0, true);
function onEnterFrame(ev:Event):void {
var requesterb:URLRequest=new URLRequest("carouselLoader.swf");
loader = null;
loader = new Loader();
loader.name ="carousel1"
//adds gallery.swf to stage at begining of movie
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader.load(requesterb);
} catch (error:SecurityError) {
trace(error);
addChild(loader);
loader.x = (stage.stageWidth - 739) * .5;
loader.y = (stage.stageHeight - 500) * .5;
// stop gallery.swf from duplication over and over again on enter frame
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
//PORTFOLIO BUTTON
//adds eventlistner so that gallery.swf can be loaded
MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
function Down(event:MouseEvent):void {
// re adds listener for contact.swf and about.swf
MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
//unloads gallery.swf from enter frame if users presses portfolio button in nav
var requester:URLRequest=new URLRequest("carouselLoader.swf");
loader = null;
loader = new Loader();
loader.name ="carousel"
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader.load(requester);
} catch (error:SecurityError) {
trace(error);
addChild(loader);
loader.x = (stage.stageWidth - 739) * .5;
loader.y = (stage.stageHeight - 500) * .5;
removeChild( getChildByName("about") );
removeChild( getChildByName("carousel1") );
// remove eventlistner and prevents duplication of gallery.swf
MovieClip(root).nav.portfolio.removeEventListener(MouseEvent.MOUSE_DOWN, Down);
//INFORMATION BUTTON
//adds eventlistner so that info.swf can be loaded
MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
function Down1(event:MouseEvent):void {
//this re-adds the EventListener for portfolio so that end user can view again if they wish.
MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
var requester:URLRequest=new URLRequest("contactLoader.swf");
loader2 = null;
loader2 = new Loader();
loader2.name ="contact"
loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader2.load(requester);
} catch (error:SecurityError) {
trace(error);
addChild(loader2);
loader2.x = (stage.stageWidth - 658.65) * .5;
loader2.y = (stage.stageHeight - 551.45) * .5;
// remove eventlistner and prevents duplication of info.swf
MovieClip(root).nav.info.removeEventListener(MouseEvent.MOUSE_DOWN, Down1);
//ABOUT BUTTON
//adds eventlistner so that info.swf can be loaded
MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
function Down3(event:MouseEvent):void {
//this re-adds the EventListener for portfolio so that end user can view again if they wish.
MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
var requester:URLRequest=new URLRequest("aboutLoader.swf");
loader3 = null;
loader3 = new Loader();
loader3.name ="about"
loader3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader3.load(requester);
} catch (error:SecurityError) {
trace(error);
addChild(loader3);
loader3.x = (stage.stageWidth - 482) * .5 - 260;
loader3.y = (stage.stageHeight - 492) * .5 - 140;
removeChild( getChildByName("carousel") );
removeChild( getChildByName("carousel1") );
// remove eventlistner and prevents duplication of info.swf
MovieClip(root).nav.about.removeEventListener(MouseEvent.MOUSE_DOWN, Down3);
stop();Andrei1,
Thank you for the helpful advice. I made the changes as you suggested but I am receiving a #1009 error message even though my site is working the way I wan it to work. I would still like to fix the errors so that my site runs and error free. This is the error I am receiving:
"TypeError: Error #1009: Cannot access a property or method of a null object reference."
I'm sure this is not the best method to unload loaders and I am guessing this is why I am receiving the following error message.
loader.unload();
loader2.unload();
loader3.unload();
I also tried creating a function to unload the loader but received the same error message and my portfolio swf was not showing at all.
function killLoad():void{
try { loader.close(); loader2.close; loader3.close;} catch (e:*) {}
loader.unload(); loader2.unload(); loader3.unload();
I have a question regarding suggestion you made to set Mouse Event to "null". What does this do setting the MouseEvent do exactly? Also, since I've set the MouseEvent to null do I also have to set the loader to null? e.g.
---- Here is my updated code ----
// variable for external loaders
var loader:Loader;
var loader1:Loader;
var loader2:Loader;
var loader3:Loader;
// makes borders resize with browser size
function resizeHandler(event:Event):void {
// resizes portfolio page to center
loader.x = (stage.stageWidth - loader.width) * .5;
loader.y = (stage.stageHeight - loader.height) * .5;
// resizes about page to center
loader3.x = (stage.stageWidth - 482) * .5 - 260;
loader3.y = (stage.stageHeight - 492) * .5 - 140;
//adds gallery.swf to stage at begining of moviie
Down();
//PORTFOLIO BUTTON
//adds eventlistner so that gallery.swf can be loaded
MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
function Down(event:MouseEvent = null):void {
// re adds listener for contact.swf and about.swf
MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
//unloads gallery.swf from enter frame if users presses portfolio button in nav
var requester:URLRequest=new URLRequest("carouselLoader.swf");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader.load(requester);
} catch (error:SecurityError) {
trace(error);
this.addChild(loader);
loader.x = (stage.stageWidth - 739) * .5;
loader.y = (stage.stageHeight - 500) * .5;
// sure this is not the best way to do this - but it is unload external swfs
loader.unload();
loader2.unload();
loader3.unload();
// remove eventlistner and prevents duplication of gallery.swf
MovieClip(root).nav.portfolio.removeEventListener(MouseEvent.MOUSE_DOWN, Down);
//INFORMATION BUTTON
//adds eventlistner so that info.swf can be loaded
MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
function Down1(event:MouseEvent = null):void {
//this re-adds the EventListener for portfolio so that end user can view again if they wish.
MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
var requester:URLRequest=new URLRequest("contactLoader.swf");
loader2 = null;
loader2 = new Loader();
loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader2.load(requester);
} catch (error:SecurityError) {
trace(error);
addChild(loader2);
loader2.x = (stage.stageWidth - 658.65) * .5;
loader2.y = (stage.stageHeight - 551.45) * .5;
loader.unload();
loader2.unload();
loader3.unload();
// remove eventlistner and prevents duplication of info.swf
MovieClip(root).nav.info.removeEventListener(MouseEvent.MOUSE_DOWN, Down1);
//ABOUT BUTTON
//adds eventlistner so that info.swf can be loaded
MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
function Down3(event:MouseEvent = null):void {
//this re-adds the EventListener for portfolio so that end user can view again if they wish.
MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
var requester:URLRequest=new URLRequest("aboutLoader.swf");
loader3 = null;
loader3 = new Loader();
loader3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
function ioError(event:IOErrorEvent):void {
trace(event);
try {
loader3.load(requester);
} catch (error:SecurityError) {
trace(error);
addChild(loader3);
loader3.x = (stage.stageWidth - 482) * .5 - 260;
loader3.y = (stage.stageHeight - 492) * .5 - 140;
loader.unload();
loader2.unload();
loader3.unload();
// remove eventlistner and prevents duplication of info.swf
MovieClip(root).nav.about.removeEventListener(MouseEvent.MOUSE_DOWN, Down3);
stop(); -
Help with load and unload swf file.
hello, just now i try, to load my file using the code snippet 'load and unload' i manage to load the next file succesfully but why my recent file still appear in the background? how do i make it gone?
When you load another SWF you're loading it 'inside' the current SWF but it appears that you want to replace the current SWF entirely with the new SWF, is that correct?
If so you should make what's usually known as a 'stub' or a loader. Make an empty project that merely acts as a loader. It should load your first SWF and when you press a button on that first SWF to load a second SWF, it should signal the 'stub' it's loaded inside to unload the first SWF and then load the second.
e.g. a stub.swf (just coding out of memory, not error checked, just to give a general idea):
// make a new loader to do all the loading of SWFs
var loader:Loader = new Loader();
// and display
addChild(loader);
// a function to load a SWF into the loader (replacing any existing SWF)
function loadSWF(path:String):void
// assure path is defined or do nothing
if (!path) return;
// load requested SWF
loader.load(new URLRequest(path));
// load initial SWF
loadSWF('/path/to/1.swf');
For your 1.swf to use the function, you're currently inside the .content property of a Loader so I believe you can just run a command like: Object(this.parent.parent).loadSWF('/path/to/2.swf');
This example obviously lacks any error checking or transitions but you can add those and season to taste. -
I want to load external swf in movieclip and next external swf should load Automatically
I want to load external swf in movieclip and next external swf should load Automatically when current swf is finished in AS3.
How can we can check total frame and current frame of imported swf in a movie clip.
any help will be appreciated
regards,
Jatin Demblain as3 you use the loader class (not movieclips) to load external swfs.
you can use an Event.COMPLETE event listener (applied to the loader's contentLoaderInfo property) to check when loading is complete and start the next swf loading.
you can use the loader's content property (caste as a movieclip) to determine info (including totalFrames) about the loaded swf's main timelnie (once loading is initialized, for the totalFrames, or complete, for some other properties like height and width).
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadcompleteF);
loader.load(new URLRequest("swf1.swf"));
var loadedSWF:MovieClip;
function loadcompleteF(e:Event):void{
loadedSWF=MovieClip(loader.content);
trace(loadedSWF.totalFrames);
Maybe you are looking for
-
Error while running Process Order API to import orders - URGENT HELP NEEDED
Hi all, I'm stuck with order import using OE_ORDER_PUB.PROCESS_ORDER api. Wanted to import a simple order in Vision database using the process order api. Figured out the right data to use, inserted into Headers and Lines Iface All tables. When callin
-
Audio Waveforms (On Certain Clips Only) Not Displaying
Long time forum-lurker, first time poster. Here's the situation: The nighttime assistant editor created a sequence of B-roll clips for an editor. On both the editor's and the assistant editor's computer, the audio waveforms for these clips are not di
-
Standard Report showing Released Budget versus Actuals
Hi All, Can any 1 tell me that is there any report that shows Released Budget versus Actuals
-
IOException: error 10054
after I run my program on emulator with monitor I get this exception: java.io.IOException: error 10054 during TCP read what is wrong?
-
No photo streaming ??
hi there, having upgraded to os5 on mac, ipod, and ipad with no problems cloud and photo working on all ok I 'm having problems with photo streaming with my iphone not reciving or sending ? sending data ok but no photos and not storing photos in pho