A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: _levelN.onEnterFrame not working.

  1. #1
    Member
    Join Date
    Apr 2004
    Location
    IA, USA
    Posts
    57

    _levelN.onEnterFrame not working.

    I have some ActionScript in a frame that loads an external SWF onto a level and then executes a function

    Code:
    loadMovieNum("index-new.swf", 2);
    trace(_level2);
    _level2.onEnterFrame = function(){
    	trace("function executed");
    }
    Unfortunately, I can't get it to work. The SWF loads at the top-left corner of my SWF, but I can't manipulate it with ActionScript after that. The first trace comes back undefined and the onEnterFrame function doesn't even work. How can I manipulate _level2 if the player won't let me access it?

    I'm using Macromedia Flash MX Professional 2004.

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    Ok so basically your saying to flash 'hey load this movie into level2'
    (now lets assume for arguments sake it take flash 3 secs to load it into level2)
    But BEFORE it has even loaded.. u are saying

    Code:
    trace(_level2);
    
    _level2.onEnterFrame = function(){
    	trace("function executed");
    }
    hence trying you are trying to access level2 even before it exists(before the swf has loaded into it)..hope that makes sense..

    to test this theory out try this instead which will put a delay before trying to access level 2

    Code:
    loadMovieNum("index-new.swf", 2);
    var nTimer:Number = setInterval(display, 5000);
    function display(){
    _level2.onEnterFrame = function(){
    	trace("function executed");
    }
    }
    This will more than likely give u the result you desire(unless of course it is taking flash even more than 5 seconds to load your external swf..

    however the above is just to get the point across..what u need to do is use the MovieClipLoader class instead...as this will broadcast events which will allow u to know when the swf has loaded...( look in the doicumentation for further events broadcast by this object)

    e.g

    Code:
    var myMCL:MovieClipLoader = new MovieClipLoader();
    var mclListener:Object = new Object();
    myMCL.addListener(mclListener);
    
    mclListener.onLoadInit = function(target_mc:MovieClip) {
    	//the swf has loaded do what u need here
      trace(_level2);
      //do 
    };
    
    
    
    myMCL.loadClip("index-new.swf", 2);
    Last edited by silentweed; 05-24-2006 at 05:48 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Member
    Join Date
    Apr 2004
    Location
    IA, USA
    Posts
    57
    You, my friend, are a god. Your explanations make sense. Your code works well. I tried it out and it works.

    Thank you so much; this helps me in so many ways.

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    hey np mate glad i cud help !!
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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