-
Access variable in MainTimeLine
I have preloader that loads another swf, game.swf.
Code:
// this code is in the preloader
var appRoot="localhost";
// load game
var request:URLRequest = new URLRequest("game.swf");
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
_loader.load(request);
How can I access preloader's variable from game.swf?
Code:
//this code in the game
var m:MovieClip = MovieClip(root);
trace ("m.appRoot=" + m.appRoot);
This gives error: m.appRoot=undefined...
Also "(root as MovieClip).appRoot" gives me the same error.
Why can't I have access to MainTimeLine's variables?
Last edited by panoss; 05-04-2015 at 05:58 AM.
-
.
Hi,
PHP Code:
// this code is in the preloader var appRoot:String = "localhost"; // load game var request:URLRequest = new URLRequest("game.swf"); var _loader:Loader = new Loader(); _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress); _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded); _loader.load(request); addChild(_loader);
function onProgress(e:ProgressEvent):void { trace("Load"); }
function onLoaded(e:Event):void { trace("Done"); }
PHP Code:
var m:MovieClip = MovieClip(parent.parent); if (m) { trace("m.appRoot=" + m.appRoot); }
-
I added one empty keyframe at the begining of the game.
The only code it has is 'stop();'.
So during loading, game is stopped at the first frame.
(so that code will be executed only after complete loading of game)
When loading is COMPLETE (function onLoaded is called), game goes to frame 2 (named "start") with: movie.gotoAndStop("start");
Now, the code that works is:
var m:MovieClip = MovieClip(parent.parent);
if (m)
{
trace("m.appRoot=" + m.appRoot);
}
So thanks a lot fruitbeard!!!
Last edited by panoss; 05-05-2015 at 07:31 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|