Copy link to clipboard
Copied
import flash.media.Sound; import flash.events.KeyboardEvent; import flash.events.Event; import flash.ui.Keyboard; import flash.net.URLRequest; import flash.display.Loader; var sound:Sound = new songmp3(); sound.play(); var loader:Loader = new Loader(); var mcExternal:MovieClip; addChild(loader); loader.load(new URLRequest("Main.swf")); stage.addEventListener(KeyboardEvent.KEY_DOWN, playGame); function playGame(event:KeyboardEvent):void { if(event.keyCode == Keyboard.ENTER) { //gotoAndPlay(121); loader.contentLoaderInfo.addEventListener(Event.COMPLETE,swfIn); } } function swfIn(event:Event):void { loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,swfIn); }
What exactly am I doing wrong? I want it so that when someone presses enter this .swf files unloads and the Main.swf loads and begins.
Copy link to clipboard
Copied
Why wouldn't this work? This is straight from Flash, do I need to publish anything beforehand or should I be able to get Main.swf to load if they are both in the same folder?
import flash.media.Sound; import flash.events.KeyboardEvent; import flash.events.Event; import flash.ui.Keyboard; import flash.net.URLRequest; import flash.display.Loader; var sound:Sound = new songmp3(); sound.play(); var loader:Loader = new Loader(); addChild(loader); var url:URLRequest = new URLRequest("Main.swf"); stage.addEventListener(KeyboardEvent.KEY_DOWN, playGame); function playGame(event:KeyboardEvent):void { if(event.keyCode == Keyboard.ENTER) { loader.load(url); } }
Copy link to clipboard
Copied
Try posting all your code again if you are still having a problem. Between the two postings things still don't add up logically.
Copy link to clipboard
Copied
Sorry, those most current code is in the latest post. I'm not sure what else I have to do to make the Main.swf load.
Copy link to clipboard
Copied
I noticed when I posted that you had changed your second posting. When you run the file, in the Player menu bar select: Control -> Disable Keyboard Shortcuts
Copy link to clipboard
Copied
When disable keyboard shortcuts is checked, I get: TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main()
Copy link to clipboard
Copied
Go into your Flash Publish settings and select the Permit Debugging option. The error should then include the line number of the offending code right after the frame number. The error itself is indicating that an object your code is targeting does not exist as far as your code sees it. If you can't figure it out you'll need to show the code you are using because at this point, you have two entirely different sets displayed. I won't be around to help though... shutting down for the day.
Copy link to clipboard
Copied
I checked Permit Debugging but I still only get that error message when I hit enter.
This is the code for my title page, it is on the main timeline:
import flash.media.Sound; import flash.events.KeyboardEvent; import flash.events.Event; import flash.ui.Keyboard; import flash.net.URLRequest; import flash.display.Loader; var music:Sound = new songmp3(); music.play(); var loader:Loader = new Loader(); this.addChild(loader); var url:URLRequest = new URLRequest("Main.swf"); stage.addEventListener(KeyboardEvent.KEY_DOWN, playGame); function playGame(event:KeyboardEvent):void { if(event.keyCode == Keyboard.ENTER) { loader.load(url); } }
My Main.fla file has no code on the timeline as I did all the code for that in an actionscript file. All these files are in the same location.