as3.0 in the Applicationdomain class to get the loaded SWF

Source: Internet
Author: User
Tags addchild

as3.0 by Applicationdomain class to Get Loaded SWF (reprinted)

First of all, review the oo composition of flash.
For Flash, we can think of any visual element as a specific instance of a class file, including a SWF file.
We can think of a SWF file as a concrete instance of a class, and it has instance objects of all other classes, such as:
We create a new Loaded.fla file, and then we create a movie clip symbol, you can do some animation inside it, open the library, click on the component right, select "link" to open "link Properties", in the class input box we type "MyClass".

This way we can--myclass the component as a class. This means that we can construct a concrete instance of this component through new and display it on the stage, such as:

var test:myclass=new myClass ();
AddChild (test);

However, the Applicationdomain class is able to obtain the application domain of the SWF file, and through the Getdefinition method can obtain a public definition from the specified application domain. The definition can be a class, a namespace, or a function definition.

Here's an example, We create a new. fla file named Doc.fla, and now we want to load the loaded.swf file published in the Doc.fla file, and then applicationdomain to get the loaded.swf file definition in MyClass file, and in Doc.fla W two specific instances. Doc.fla document Class "Sunneon":

Package {
Import Flash.display.Sprite;
Import Flash.display.Loader;
Import Flash.display.LoaderInfo;
Import Flash.net.URLRequest;
Import Flash.display.MovieClip;
Import flash.events.Event;
Import Applicationdomain Class
Import Flash.system.ApplicationDomain;

public class Sunneon extends Sprite
{
private var swfpath:string= "loaded.swf";
private Var Loader:loader;
private Var ur:urlrequest;
Public Function Sunneon ()
{
Loader=new loader ();
Ur=new urlrequest (Swfpath);
Add the Load complete event, event handler function Oncl
Loader.contentLoaderInfo.addEventListener (EVENT.COMPLETE,ONCL);
Loader.load (UR);
}
Loads the handler for the completed event, processing the application domain in the loaded SWF file
Private Function Oncl (event:event): void{
Loaderinfo object hosts the information loaded into the SWF file
var swftarget:loaderinfo=event.target as Loaderinfo;
Swftarget read-only property Applicationdomain returns a Applicationdomain
To create an application domain for the loaded SWF
var appdomain:applicationdomain=swftarget.applicationdomain as Applicationdomain;
The Getdefinition method obtains a public definition from the specified application domain.
The definition can be a class, a namespace, or a function definition.
where "MyClass" is the class in the linked property of the movie clip in the loaded SWF file
var mcclass:class=appdomain.getdefinition ("MyClass") as Class;
Creates a Mcclass instance and returns a movie clip object
var mymca:movieclip= (new Mcclass ()) as MovieClip;
var mymcb:movieclip= (new Mcclass ()) as MovieClip;
Setting properties for newly created objects
mymca.x=10;
mymca.y=100;
mymca.alpha=0.5;

mymcb.x=0;
mymcb.y=200;
mymcb.width=70;
Make an object appear in the container Sunneon
AddChild (MYMCA);
AddChild (MYMCB);
}
}
}

as3.0 in the Applicationdomain class to get the loaded SWF

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.