A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: How to check if an swf file is loaded

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    38

    How to check if an swf file is loaded

    (I don't want to check ProgressEvent.PROGRESS while loading, but, after it's loaded, to check if it's loaded so it won't be reloaded)

    In my preloader I'm loading a file, called 'settings.swf' with this code:
    Code:
    // this code is in preloader
    var request:URLRequest=new URLRequest("settings.swf");
    var _loader:Loader = new Loader();
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
    _loader.load(request);
    
    function onLoaded(e:Event):void {
    	var movie:* =LoaderInfo(e.currentTarget).content;
    	Container3.addChild(movie); // Container3 is a MovieClip on MainTimeLine
    }
    The movie is added with a name like 'instance138' or something like this.
    But I can't check if it's loaded with a name like this, randomly created.
    I tried to change it's name with 'movie.name="settings" ' but it gave me an error:
    "Error: Error #2078: The name property of a Timeline-placed object cannot be modified."

    So, how could I check if a movieclip is loaded? (I suppose changing it's name is impossible)
    Last edited by panoss; 05-13-2015 at 11:48 AM.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    if you make movie a member var from the beginning, you can access it using that name.

    PHP Code:
    var request:URLRequest = new URLRequest("settings.swf");
    var 
    _loader:Loader = new Loader();
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETEonLoaded);
    _loader.load(request);
    //Container3.addChild(_loader);

    var movie:MovieClip;

    function 
    onLoaded(e:Event):void
    {
        
    movie MovieClip(e.target.content);
        
    Container3.addChild(movie);
        if (
    movie)
        {
            for (var 
    i:Number 0Container3.numChildreni++)
            {
                var 
    ob Container3.getChildAt(i);
                
    trace(ob.name);
                
    trace(ob.x);
                
    trace(ob.y);
                
    trace(ob.width);
                
    trace("----------");
            }
            
    movie.+= 200
            trace
    (movie);
            
    //movie.parent.removeChild(movie);
        
    }


  3. #3
    Member
    Join Date
    Aug 2008
    Posts
    38
    I was not clear enough, so I 'll have to add some info.
    In the third frame of the preloader, lays the (above quoted) code of the loader.
    So when it enters the third frame, the code is executed and the movie is loaded.

    BUT, I want firstly to check if the movie is loaded, and if it is, the code NOT to be executed.
    Something like: if (Container3.getChildByName("settings") == null) { //code; }
    Last edited by panoss; 05-13-2015 at 01:15 PM.

  4. #4
    Member
    Join Date
    Aug 2008
    Posts
    38
    What I discovered is that dynamically loaded movieClips get unloaded when I exit the frame in which they are added.
    Let me explain what mean.

    I have the preloader.swf, it has 3 frames.

    In frame 2 I have a movieClip called 'Container2'.
    When the application enters frame 2, on Container2 is added the 'settings.swf'.

    In frame 3 I have a movieClip called 'Container3'.
    When the application enters frame 3, on Container3 is added the 'game.swf'.
    Now, the 'settings.swf' does not exist, it's unloaded and destroyed, right?

    So if i execute 'gotoAndPlay(2)' the settings.swf will not be seen.
    I 'll have to reload it.
    Am I correct?

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,


    You might find it easier using only one frame save having to reload things all the time, just addChild and removeChild or even use the visible setting.
    Try attaching your files as I say again, it is very hard trying to guess what you have set up.

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