AS3 button help
I'm having some trouble getting a button to load and unload an incoming swf file.
http://www.scottberks.com/clientwork/flash/flash.zip
I'm using CS6.
Any help would be REALLY appreciated.
I'm having some trouble getting a button to load and unload an incoming swf file.
http://www.scottberks.com/clientwork/flash/flash.zip
I'm using CS6.
Any help would be REALLY appreciated.
Few quick things.. You're running loadScene() right in a frame script which is typically fine but just for safety it's often advised to wait until entering a frame to fire off your first script, especially when it accesses the stage.
e.g.
addEventListener(Event.ENTER_FRAME, onEF);
function onEF(e:Event):void {
removeEventListener(Event.ENTER_FRAME, onEF);
// stage is definitely ready here, run the function
loadScene();
}
Outside that, you're not doing any error checking on the Loader's request. You can find plenty of examples of checking for all sorts of load errors on the Loader page:
Loader - Adobe ActionScript® 3 (AS3 ) API Reference
Specifically keep in mind you add the error listeners to the .contentLoaderInfo property of the Loader object myLoader:
After that, your button code in backButtonClick() function is making a new URLRequest, asking the loader "singleLoader" you made to load it and then is running addChild(myLoader) again instead of the "singleLoader". If your intention is literally to reload it, you should just be using "myLoader" again rather than "singleLoader".
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.