Load SWF within SWF
Monkey Targets Forums/Flash/Load SWF within SWF
| ||
Ok, simple question (I hope) How easy is it to load a SWF file from within an SWF file? So, if you click on button, or press a key (some trigger) it pauses the current SWF and loads another SWF. When this SWF finishes (or exits) the previous SWF resumes? Direct in ActionScript, this would be done as var myLoader:Loader = new Loader(); var url:URLRequest = new URLRequest("ExternalSWF.swf"); myLoader.load(url); addChild(myLoader); But I can not figure out how to do this in MonkeyX |
| ||
I'm afraid you probably need to implement your own native code using extern. Writing a small piece of code and importing it via Import and then doing a Extern..Public block should hopefully do the trick. |
| ||
Hi Pharmhaus, I was thinking the same thing. Creating an external .as file with the above code in a function, and a separate function to handle a call back (for when the 2nd SWF needs to exist, so it can close it and unload it). I'll give it a try tonight. |
| ||
Ok, I got it moving forward, but its not easy. And i've almost given up several times. I've created a file functions.as with the following code function LoadChildSWF(aFileName:String, aPosX:int, aPosY:int):void { var stage:Stage=BBFlashGame.FlashGame().GetDisplayObjectContainer().stage; var url:URLRequest = new URLRequest(aFileName); var myLoader:Loader = new Loader(); myLoader.load(url); stage.addChild(myLoader); myLoader.x = aPosX; myLoader.y = aPosY; and added the following to my ,monkey file Import "functions.as" Extern Function LoadChildSWF( aFileName:String, aPosX:Int, aPosY:Int ) Public Method OnUpdate() If KeyHit (KEY_DOWN ) LoadChildSWF( "Myswf.swf", 50, 50 ) UpdateAsyncEvents End This loads the Myswf.swf and positions it at 50,50 and it runs on top of the main SWF. My problem now is unloading it when its finished. |