A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Access variable in MainTimeLine

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    38

    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.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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.PROGRESSonProgress);
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETEonLoaded);
    _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);


  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    38
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center