AS3 loader copy loaded picture instance program

Source: Internet
Author: User
Tags addchild


Let's take a look at loader: in ActionScript 3.0, it's not the ActionScript 2.0 Moviecliploader and Loadvars classes, but the loader and Urlloader classes.


The properties of the Loader class allow you to set the content to be loaded and monitor its loading progress at run time.

Setting the properties of the Loader class with ActionScript overrides the parameter of the same name set in the property inspector or the component Inspector.

Each component class has a version property, which is a class property. Class properties can only be used for the class itself. The Version property returns a string that indicates the build of the component. To access this property, use the following code:

Trace (mx.controls.Loader.version);

Method summary for the Loader class

The following table lists the methods for the Loader class.

Loader.load ()

Loads the content specified by the Contentpath property.

Attention

Code Trace (myloaderinstance.version); return to undefined.

Use loader to consider the security model for Flash Player and Adobe AIR:

Cases

The code is as follows Copy Code

Package net.smilecn.studyloader{

Import Flash.display.Sprite;

public class Submainform extends sprite{

Public Function Submainform (): void{

}
}

}

You can load content from any accessible source.

Loading is not allowed if the calling SWF file is in a network sandbox and the file to be loaded is local.

System.allowinsecuredomain () method allows you to arrange across scripts, otherwise a SWF file in another security sandbox cannot perform a cross script operation on it.

If the content being loaded is a AVM1 swf file (written in ActionScript 1.0 or 2.0), the AVM2 swf file (written in ActionScript 3.0) cannot perform a cross script operation on it. However, communication can be achieved between two SWF files by using the LocalConnection class.

If the content being loaded is an image, the SWF file outside the security sandbox cannot access its data unless the SWF file's domain is contained in the Cross-domain policy file for the image's original domain.

Movie clips in a sandbox that can interact only with content in the local file system cannot use scripts for movie clips in a sandbox that can only interact with remote content, and vice versa.

However, in the Apollo runtime, the contents of the application security sandbox, which are installed with the Apollo application, are not bound by these security restrictions.

Cases

The code is as follows Copy Code

Package
{
Import Flash.display.Loader;
Import Flash.display.Sprite;
Import flash.events.Event;
Import Flash.net.URLLoader;
Import Flash.net.URLLoaderDataFormat;
Import Flash.net.URLRequest;
Import Flash.system.LoaderContext;
Import Flash.utils.ByteArray;

/**
* ...
* @author amyflash.com
*/
public class Main extends Sprite
{

Public Function Main (): void
{
if (stage) init ();
else AddEventListener (event.added_to_stage, init);
}
private var urlloader:urlloader = new Urlloader ();
private var loader1:loader = new Loader ();
private var loader2:loader = new Loader ();
Private Function init (e:event = null): void
{
RemoveEventListener (Event.added_to_stage, init);
Entry point
var _url:string = "Yun_qi_img/1.jpg";
Urlloader.dataformat = urlloaderdataformat.binary;
var urlrequest:urlrequest = new URLRequest (_url);

Urlloader.load (URLRequest);
Urlloader.addeventlistener (Event.complete, doshow);

}

Private Function Doshow (_evt:event): void
{
Loader1.loadbytes (_evt.target.data);
Loader1.contentLoaderInfo.addEventListener (Event.complete, swfloadcomplete);
Loader2.loadbytes (_evt.target.data);
Loader2.contentLoaderInfo.addEventListener (Event.complete, SwfLoadComplete2);
}

Private Function Swfloadcomplete (e:event): void
{
AddChild (Loader1);
}

Private Function SwfLoadComplete2 (e:event): void
{
AddChild (LOADER2);
loader2.x = 100;
}
}

}

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.