About how to load external SWF in ActionScript 3
Disclaimer: Anyone and organizations are welcome to repost the articles in this blog, but the original links and author information must be marked.
Link: http://blog.csdn.net/li_007/archive/2009/03/27/4031073.aspx
Pioneering little turtle -------> csdn
For external SWF loading, corner 3 has changed the implementation method of corner stone 2/1. Of course, the method provided by corner stone is more friendly, effective, and easier to control external SWF files. For example, after loading, you can obtain the SWF file's frame number, some properties of the SWF file, information about the loading process, etc. Of course, if you can obtain the data, you can easily control the playback and pause of SWF. Here let's talk about it. On the Forum, many people say that they can use the code below to obtain the frame number of an external SWF file as 1 or cannot be obtained.
This. _ loader. contentloaderinfo. addeventlistener (event. complete, onloadcompleted); <br/> private function onloadcompleted (EVT: event = NULL): void <br/>{< br/> This. _ display. visible = true; </P> <p> This. _ loader. contentloaderinfo. removeeventlistener (event. complete, onloadcompleted); </P> <p> This. _ totalframes = moviames (evt.tar get. content ). totalframes; </P> <p> evt.tar get. content. addeventlistener (event. enter_frame, onloaderenterframe); <br/>}
In fact, we should pay attention to this point. In event 3, the SWF of as2/1 is converted to the avm1movie type and cannot be converted to the movieclip type. Of course, the total number of frames cannot be obtained, you can use the actionscriptversion attribute of loadinfo to obtain the version of the currently loaded SWF's ActionScript (about loader, loaderinfo, and URLRequest to be discussed), for example:
Figure 1. SWF loading information of ActionScript 2
Now let's look at the debugging of loading the SWF file with actionscriptversion = 3:
Figure 2. SWF loading information of ActionScript 3
Now let's talk about flash. display. loader, Flash. display. loaderinfo, and Flash. net. URLRequest. First, you need to use load to load external SWF, pics, and other display objects. If you are loading binary data in XML, you need to use urlloader. URLRequest is the URL of the object to be loaded. For the loaderinfo object, see the description of Adobe docs:
The loaderinfo class provides information about a loaded SWF file or a loaded image file (JPEG, GIF, or PNG ). loaderinfo objects are available for any Display object. the information provided between des load progress, the URLs of the loader and loaded content, the number of bytes total for the media, and the nominal height and width of the media.
You can access loaderinfo objects in two ways:
- The
contentLoaderInfo
Property of a flash. display. loader object-contentLoaderInfo
Property is always available for any loader object. For a loader object that has not calledload()
OrloadBytes()
Method, or that has not sufficiently loaded, attempting to access attributes of the properties ofcontentLoaderInfo
Property throws an error.
- The
loaderInfo
Property of a display object.
ThecontentLoaderInfo
Property of a loader object provides information about the content that the loader object is loading, whereasloaderInfo
Property of a displayobject provides information about the root SWF file for that display object.
When you use a loader object to load a display object (such as a SWF file or a bitmap),loaderInfo
Property of the display object is the same ascontentLoaderInfo
Property of the loader object (DisplayObject.loaderInfo = Loader.contentLoaderInfo
). Because the instance of the main class of the SWF file has no loader object,loaderInfo
Property is the only way to access the loaderinfo for the instance of the main class of the SWF file.
Each Display object has the loaderinfo attribute. It provides the loading object's high width, number of bytes, loading progress, loading object URL, and the previously mentioned actionscriptversion. For a loaded SWF object,contentLoaderInfo
Attribute to provide information about the content loaded by the loader object, while the displayobjectloaderInfo
Property provides information about the root SWF file of the display object. TheloaderInfo
Attribute reference and loader objectcontentLoaderInfo
The loaderinfo object with the same attributes. In other words, the loaderinfo object is the shared object between the loaded object file and the loaded loader object. Because the primary class instance of the SWF file does not have a loader objectloaderInfo
The property is the only method used to access loaderinfo of the SWF file's main class instance. The content attribute of the loader object indicates the root Display object of the loaded file, therefore, these attributes can easily access the loaded objects and loaded objects. The evt.tar get. loader content, contenloaderinfo, and loaderinfo attributes in Figure 2 can be understood. (assume that you know the event Stream Mechanism of event 3 and the currenttarget and target attributes ). After reading the evt.tar get. loader. content value, you will be able to get the total number of frames loaded with SWF. After loading the file as follows:
Figure 3. debug SWF after being loaded
By the way, when we import the FLV file into FLA, there are two options: import to stage and import video. They seem to be the same, but they are actually different, in import to stage, it is directly imported to maintimeline, while import video is converted into a movieclip. Let's look at another example of using the SWF of import to stage for loading and debugging:
Figure 4 Import to stage to debug the SWF file generated by fla
PS: The following is an Adobe docs description of the avm1movie type: