AS3 - Access objects from external SWF files
Download accessExternalSwf.zip, 25 KB (Flash CS4 professional)
loadSWFs.as
// Developed by Anil kumar N D
// anilkumarnd@gmail.com
// ActionScript 3.0
// 30-April-2009
// http://flash-workshop.blogspot.com/package {
import flash.display.MovieClip;
import flash.display.Shape;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;public class loadSWFs extends MovieClip {
var shp_mainLine:Shape;
var shp_statusLine:Shape;
var txt_status:TextField;
var mc_loadedMovieClip:MovieClip = new MovieClip();
public function loadSWFs():void {
mc_access.buttonMode=true;
mc_pass.buttonMode=true;
mc_access.mouseChildren=false;
mc_pass.mouseChildren=false;
mc_load.mouseChildren=false;
mc_load.buttonMode=true;
mc_access.visible = false;
mc_pass.visible = false;
mc_load.addEventListener(MouseEvent.CLICK,loadSWF);mc_access.addEventListener(MouseEvent.CLICK,accessData);
mc_pass.addEventListener(MouseEvent.CLICK,passData);
addChild(mc_loadedMovieClip);
}
function loadSWF(IN_Event:MouseEvent):void {
mc_load.visible = false;
mc_access.visible = true;
mc_pass.visible = true;
createStatusBar();var loader:Loader=new Loader ;
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
loader.load(new URLRequest("swf/externalSWF.swf"));
}function accessData(IN_Event:MouseEvent):void {
var mc_object:MovieClip=MovieClip(mc_loadedMovieClip.getChildAt(0));
txt_mainMovie.text=mc_object.txt_external.text;
}function passData(IN_Event:MouseEvent):void {
var mc_object:MovieClip=MovieClip(mc_loadedMovieClip.getChildAt(0));
mc_object.txt_external.text = txt_mainMovie.text;
}function completeHandler(IN_Event:Event):void {
mc_loadedMovieClip.addChild(IN_Event.target.content);
this.removeChild(shp_mainLine);
this.removeChild(shp_statusLine);
this.removeChild(txt_status);
}
function progressHandler(IN_Event:ProgressEvent):void {
var percent:Number=IN_Event.bytesLoaded*100/IN_Event.bytesTotal;
shp_statusLine.scaleX=percent/100;
txt_status.text=Math.round(percent)+" %";
}
function createStatusBar():void {
shp_mainLine=new Shape ;
shp_mainLine.graphics.lineStyle(8,0x00CC00);
shp_mainLine.graphics.lineTo(200,0);
shp_mainLine.x=stage.stageWidth/2-shp_mainLine.width/2;
shp_mainLine.y=stage.stageHeight/2;
shp_statusLine=new Shape ;
shp_statusLine.graphics.lineStyle(1,0xFFFFFF);
shp_statusLine.graphics.lineTo(200,0);
shp_statusLine.scaleX=.01;
shp_statusLine.x=stage.stageWidth/2-shp_mainLine.width/2;
shp_statusLine.y=stage.stageHeight/2;
txt_status=new TextField ;
txt_status.autoSize=TextFieldAutoSize.CENTER;
txt_status.selectable=false;
txt_status.textColor=0x000000;
txt_status.y=shp_mainLine.y+10;
txt_status.x=shp_mainLine.x+shp_mainLine.width/2;
this.addChild(shp_mainLine);
this.addChild(shp_statusLine);
this.addChild(txt_status);
}
}
}
externalSWF.as
// Developed by Anil kumar N D
// anilkumarnd@gmail.com
// ActionScript 3.0
// 30-April-2009
// http://flash-workshop.blogspot.com/package {
import flash.display.MovieClip;
import flash.events.MouseEvent;public class externalSWF extends MovieClip {
public function externalSWF():void {
mc_access.buttonMode=true;
mc_pass.buttonMode=true;
mc_access.mouseChildren=false;
mc_pass.mouseChildren=false;
mc_access.addEventListener(MouseEvent.CLICK,accessData);
mc_pass.addEventListener(MouseEvent.CLICK,passData);
}function accessData(IN_Event:MouseEvent):void {
var tempObject=this.parent.parent;
this.txt_external.text=tempObject.txt_mainMovie.text;
}
function passData(IN_Event:MouseEvent):void {
var tempObject=this.parent.parent;
tempObject.txt_mainMovie.text=this.txt_external.text;
}
}
}
Comments
I feel happy with your application but, is not opening in CS3 which i am working in presently.
Thanks,
Swathi
But how would I do it if I only wanted on transistion like Blinds and I wanted the images in order not random.
Thanks for the help.
flash website developer