简体   繁体   中英

AS3 Loading external swf from AN externally loaded swf - Accessing Children?

EDIT

UPDATE MARCH 12TH 2012: This is done using AIR FOR ANDROID USING CS5.5. I need access to the vars in the newly EXTERNALLY LOADED SWF files that are hosted on a web server and I need to have the APP on my phone access them. I am beginning to this is not possible.

------------------------------------------------------------------------------

My Main Stage swf loads another one:

SWF 1

var TheContent:Loader = new Loader();
    TheContent.load(new URLRequest("http://MyWebsite.com/swf2.swf"));

/// In this SWF 1 above I NEED TO KNOW WHAT CODE can see if other content is loaded and control it when loaded. But its tricky because I am loading external content from an externally loaded swf.

Here is the code in SWF 2

var TheMenu:Loader = new Loader();
TheMenu.load(new URLRequest("http://MyWebsite.com/MenuBar.png")); // you were missing a "

In the first SWF 1 I want to know if the MenuBar.png has loaded and how to control it. So for example in SWF 1 I might put code like this...

    if(TheContent.MenuBar) /// IS LOADED? THEN...
    {
        MenuBar.alpha = .3;
        MenuBar.x = 33;
        etc...
    }

You can save the progress value into a public variable, that can be acessed through the swf.

The follow code for SWF 2:

import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.net.URLRequest;

public class YourClassName
{
    /**This will get a progress number of your file**/
    public var fileProgress:Number = 0;
    /**This will get the file size**/
    public var fileTotalBytes:Number = 0;

    public function YourClassName()
    {           
        var TheMenu:Loader = new Loader();
        TheMenu.addEventListener(ProgressEvent.PROGRESS, onProgressHandler, false, 0, true);
        TheMenu.load(new URLRequest("http://MyWebsite.com/MenuBar.png"));

    }

    protected function onProgressHandler(event:ProgressEvent):void{
        fileProgress = event.bytesLoaded;
        fileTotalBytes = event.bytesTotal;
    }
}`

The follow code for SWF 1:

public function printStatus():void{

        //Returs file`s progress
        trace("Progresss: "+swf1.fileProgress);

        //Return file`s size
        trace("File size: "+swf1.fileTotalBytes);
    }

I hope this can help you!

First Point, it seems that your whole structure is proberly not the best approach. From my under standing your question is:

(Main Movie) loads secondary(Movie) then (SECONDARY) Movie loads its secondary (movie);

then you want the first movie to control the second movie on condition the third movie is %100 and ready for action

This will target from the loaded Swf to the main SWF

      MovieClip(parent.parent).ParentFunction();    // or the 3rd movie would be 
      MovieClip(parent.parent.parent).ParentFunction();

I have made you a file on my server http://www.gamezslave.net/SampleAS3/

Just open the main movie.swf you will see it load the other two movies inside of each other as you wanted then it plays an animation in the first movie to let you know the 3rd movie has finished downloading. Let me know how you go please as i took 15 minutes putting it together for you.

in the zip (contains all source files 3x "SWF" and 3x "html pages");

thanks BJM Sydney

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM