AS3.0 Gets the loaded application domain through the Applicationdomain class

Source: Internet
Author: User
Tags addchild definition function definition domain

First, review the oo makeup of flash.
For Flash, we can think of any visual component 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 all the instance objects of other classes, such as:
We create a new Loaded.fla file, and then we build a movie clip symbol, you can do some animation inside of it, open the library

, click the component right, select link to open link properties, and in the class input box we type "MyClass".
So we can take this component as a class--myclass. Which means we can build a concrete instance of this component with new.

and displayed 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, through the Getdefinition method, from the specified application domain

Gets a public definition. The definition can be a class, a namespace, or a function definition.

For example, let's create a new. fla file named Doc.fla, which we now want to download in the Doc.fla file

loaded.swf file, and then through Applicationdomain to get the definition of MyClass file in loaded.swf file, and in Doc.fla

New two concrete instances. DOC.FLA's 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 Load completion event, event handler function Oncl
Loader.contentLoaderInfo.addEventListener (EVENT.COMPLETE,ONCL);
Loader.load (UR);
}
//load the handler function of the completion event to process the application domain
Private function Oncl (event:event) in the loaded SWF file: void{
// The Loaderinfo object hosts the information that is loaded into the SWF file
var swftarget:loaderinfo=event.target as Loaderinfo;
Swftarget read-only property Applicationdomain returns a Applicationdomain
//Creating an application domain for 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
Var mcclass:class=appdomain.getdefinition ("MyClass") as class in the movie clip link attribute in the loaded SWF file;
Creates a Mcclass instance and returns the movie clip Object
var mymca:movieclip= (new Mcclass ()) as MovieClip;
var mymcb:movieclip= (new Mcclass ()) as MovieClip;
//For newly createdobject to make a property
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);
}
}
}










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.