AS3 load External SWF movie file implementation detailed

Source: Internet
Author: User
Tags addchild getcolor

The easiest way to do it

The code is as follows Copy Code

var my_urlloader:loader=new Loader ();
My_urlloader.load (New URLRequest ("swf.swf"));
My_urlloader.contentLoaderInfo.addEventListener (event.complete,_show);
function _show (e:event): void {
AddChild (My_urlloader);
}

Example 2

The code is as follows Copy Code

Import Flash.net.URLRequest;
Import Flash.display.Loader;
Import flash.events.Event;
Import flash.events.ProgressEvent;

var mc:movieclip = new MovieClip ();

Function Startload ($swf: String)
{
var ldr:loader = new Loader ();
var mrequest:urlrequest = new URLRequest ($ SWF);
Ldr.contentLoaderInfo.addEventListener (Event.complete, Oncompletehandler);
Ldr.contentLoaderInfo.addEventListener (progressevent.progress, Onprogresshandler);
Ldr.load (mrequest);
}

Function Oncompletehandler ($e: Event)
{
MC = $e. Currenttarget.content as MovieClip;
AddChild ($e . currenttarget.content);
}
Function Onprogresshandler ($e:P rogressevent)
{
var percent:number = $e. bytesloaded/ Mprogress.bytestotal;
Trace (percent);
}
Startload ("mouseactions.swf");

The top 22 is simple to load, and if you want to implement AS3 loading an external SWF file and interacting with it we can follow the following method.

The loader class loads the. swf file and then accesses it through the content property of the loader instance

The code is as follows Copy Code

Externalmovie Code:

Package {
Import Flash.display.Sprite;
Import Flash.display.Shape;
public class Externalmovie extends Sprite {
private Var _color:uint=0x000000;
private Var _circle:shape;
Public Function Externalmovie () {
Updatedisplay ();
}
Private Function Updatedisplay (): void {
If circle is not created, it is created and displayed
if (_circle = = null) {
_circle=new Shape;
AddChild (_circle);
}
To redraw and populate the previously drawn content
_circle.graphics.clear ();
_circle.graphics.beginfill (_color);
_circle.graphics.drawcircle (100,100,40);
}
Change color
Public Function SetColor (color:uint): void {
_color=color;
Updatedisplay ();
}
Get color
Public Function GetColor (): UINT {
return _color;
}
}
}


Loaderexample Code:

Package {
Import flash.display.*;
Import Flash.net.URLRequest;
Import flash.events.Event;
public class Loaderexample extends Sprite {
private Var _loader:loader;
Public Function Loaderexample () {
Create loader and display
_loader = new loader ();
AddChild (_loader);
Interaction events added to a loaded SWF file
_loader.contentloaderinfo.addeventlistener (Event.init,handleinit);
Loading external files
_loader.load (New URLRequest ("externalmovie.swf"));
}
Trigger this function when the file is loaded
Private Function Handleinit (event:event): void {
This is set to * means not knowing what type to load in advance.
var movie:* = _loader.content;
Get color value, display as 0
Trace (Movie.getcolor ());
Set color
Movie.setcolor (0X016BE2);
}
}
}

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.