AS3: Always reloading swf? Why? - actionscript-3

I have a Homepage, which plays a mainSWF. In this mainSWF I have a loader, that loads external swfs from my server. With a button you can unload this external swfs an load a different one. Some of this swfs are 30mb big.
So, here is my problem:
The external SWFs are never saved temporary, or something like that. So you have to load all the 30mb everytime again. Is there a workaround or a configuration or something?
Thanks for answering!
var _swfLoader:Loader;
var _swfContent:MovieClip;
function loadSWF(path:String):void {
var _req:URLRequest = new URLRequest();
_req.url = path;
_swfLoader = new Loader();
setupListeners(_swfLoader.contentLoaderInfo);
_swfLoader.load(_req);
}
function setupListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, addSWF);
dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
}
function preloadSWF(event:ProgressEvent):void {
var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
// swfPreloader.percentTF.text = _perc + "%";
}
function addSWF(event:Event):void {
event.target.removeEventListener(Event.COMPLETE, addSWF);
event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
_swfContent = event.target.content;
_swfContent.screen_demo_close_btn.addEventListener(MouseEvent.CLICK, unloadSWF);
addChild(_swfContent);
}
function unloadSWF(event:Event):void {
if (MovieClip(root).onDemo == 1) {
MovieClip(root).resetDevices();
_swfLoader.unloadAndStop();
removeChild(_swfContent);
_swfContent = null;
MovieClip(root).onDemo = 0;
}
}

Related

ActionScript3 remove child error

I recently have been converting an as2 fla to as3 (new to AS3) and have the entire thing working on export, but I am getting an error when I try to remove previously loaded swf's before a new swf is loaded
ArgumentError: Error #2025: The supplied DisplayObject
must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-11()
I know the error relates to my removeChild code here:
`stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void
{
if(vBox.numChildren !=0){
// swfLoader.unloadAndStop();
vBox.removeChild(swfLoader);// empty the movieClip memory
}
}`
However, I cannot seem to find a suitable rewrite for this code that will work and not have an error. This code IS working, so I'm not sure if it would be worth my time to fix this error, or just leave it. I've already messed with it for a couple days, so at this point it's just frustrating me that I cannot fix it.
The stage mouse click listener is useful in this case because I have a back button not shown in this code that clears the loaded swf's before moving to another scene.
Does anyone see a simple solution for this, or do you think it is unnecessary to pursue since the code does what I require?
ENTIRE CODE:
function launchSWF(vBox, vFile):void {
var swfLoader:Loader = new Loader();
var swfURL:URLRequest = new URLRequest(vFile);
swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
swfLoader.load(swfURL);
function loadProdComplete(e:Event):void {
trace("swf file loaded");
vBox.removeChild(preLoader);
vBox.addChild(swfLoader);
currentSWF = MovieClip(swfLoader.content);
currentSWF.gotoAndPlay(1);
currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);
swfLoader.x = 165;
swfLoader.y = 15;
function checkLastFrame(e:Event):void {
if (currentSWF.currentFrame == currentSWF.totalFrames) {
currentSWF.stop();
// trace("DONE");
}
}
}
var preLoader:loader = new loader();
preLoader.x = 450;
preLoader.y = 280;
vBox.addChild(preLoader);
function onProgressHandler(event:ProgressEvent){
var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
//preLoader.bar.scaleX = dataAmountLoaded/100;
preLoader.lpc.text= int(dataAmountLoaded)+"%";
//trace(preLoader.bar.scaleX );
}
//NEW ERRORS BUT WORKING
stage.addEventListener(MouseEvent.CLICK, removeSWF);
function removeSWF (e:MouseEvent):void
{
if(vBox.numChildren !=0){
// swfLoader.unloadAndStop();
vBox.removeChild(swfLoader);// empty the movieClip memory
}
}
}
var container:MovieClip = new MovieClip();
var currentSWF:MovieClip = new MovieClip();
fall_b.addEventListener(MouseEvent.CLICK, fall_bClick);
function fall_bClick(e:MouseEvent):void {
var swfFile:String = 'load/fall.swf';
launchSWF(container, swfFile);
addChild(container);
}
face_b.addEventListener(MouseEvent.CLICK, face_bClick);
function face_bClick(e:MouseEvent):void {
var swfFile:String = 'load/face.swf';
launchSWF(container, swfFile);
addChild(container);
}
rott_b.addEventListener(MouseEvent.CLICK, rott_bClick);
function rott_bClick(e:MouseEvent):void {
var swfFile:String = 'load/rottgut.swf';
launchSWF(container, swfFile);
addChild(container);
}
//MORE SWFS...
Any advice anyone has is appreciated
First of all function launchSWF(vBox, vFile):void { isn't closed. You've also got function inside functions which is easy enough for you to solve if you click the lines the curly brackets start and end on to track them.
I can't see anything wrong with the code you said has an error but I'm guessing this isn't all the code. If you using Flash Professisonal you can use permit debugging to show the line the error is on.
EDIT: Please note this hasn't been tested as I'm on my mobile writing out code. That being said this should now work:
var container:MovieClip;
var currentSWF:MovieClip;
var swfFile:String;
var swfLoader:Loader;
var preLoader:Loader;
var swfURL:URLRequest;
init();
function init():void {
preLoader = new Loader();
preLoader.x = 450;
preLoader.y = 280;
vBox.addChild(preLoader);
container = new MovieClip();
currentSWF = new MovieClip();
fall_b.addEventListener(MouseEvent.CLICK, fall_bClick);
face_b.addEventListener(MouseEvent.CLICK, face_bClick);
rott_b.addEventListener(MouseEvent.CLICK, rott_bClick);
stage.addEventListener(MouseEvent.CLICK, removeSWF);
}
function launchSWF(vBox, vFile):void {
swfLoader = new Loader();
swfURL = new URLRequest(vFile);
swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
swfLoader.load(swfURL);
}
function loadProdComplete(e:Event):void {
trace("swf file loaded");
vBox.removeChild(preLoader);
vBox.addChild(swfLoader);
currentSWF = MovieClip(swfLoader.content);
currentSWF.gotoAndPlay(1);
currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);
swfLoader.x = 165;
swfLoader.y = 15;
}
function checkLastFrame(e:Event):void {
if (currentSWF.currentFrame == currentSWF.totalFrames) {
currentSWF.stop();
// trace("DONE");
}
}
function onProgressHandler(event:ProgressEvent) {
var dataAmountLoaded:Number = (event.bytesLoaded / event.bytesTotal * 100);
//preLoader.bar.scaleX = dataAmountLoaded/100;
preLoader.lpc.text = int(dataAmountLoaded)+"%";
//trace(preLoader.bar.scaleX );
}
function removeSWF (e:MouseEvent):void {
if(vBox.numChildren !=0){
//swfLoader.unloadAndStop();
vBox.removeChild(swfLoader);// empty the movieClip memory
}
}
function fall_bClick(e:MouseEvent):void {
swfFile = 'load/fall.swf';
launchSWF(container, swfFile);
addChild(container);
}
function face_bClick(e:MouseEvent):void {
swfFile = 'load/face.swf';
launchSWF(container, swfFile);
addChild(container);
}
function rott_bClick(e:MouseEvent):void {
swfFile = 'load/rottgut.swf';
launchSWF(container, swfFile);
addChild(container);
}
I have this rewritten. I could not get the vBox errors cleared in the original code, and I was getting many other errors with what was posted. The vBox code was seen on a tutorial. I think it was supposed to reference the loader for the preloader and the swf, and vFile was for the actual .swf. The following code preloads multiple swfs and clears them with no errors. I appreciate your help AntBirch. I'm beginning to understand loaders in as3 a little more now.
//LOAD FIRST PIECE ON OPEN (required to removeChild later)
var swfLoader:Loader = new Loader();
var defaultSWF:URLRequest = new URLRequest("load/fall.swf");
swfLoader.load(defaultSWF);
swfLoader.x = 165;
swfLoader.y = 15;
addChild(swfLoader);
//PRELOADER
var preLoader:loader = new loader();
preLoader.x = 450;
preLoader.y = 280;
function loadProdComplete(e:Event):void {
trace("swf file loaded");
removeChild(preLoader);
addChild(swfLoader);
}
function onProgressHandler(event:ProgressEvent){
var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
preLoader.lpc.text= int(dataAmountLoaded)+"%";
}
//BUTTONS
function btnClick(event:MouseEvent):void {
swfLoader.unloadAndStop();
removeChild(swfLoader);
swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
addChild(preLoader);
var newSWFRequest:URLRequest = new URLRequest("load/" + event.target.name + ".swf");
swfLoader.load(newSWFRequest);
swfLoader.x = 165;
swfLoader.y = 15;;
addChild(swfLoader);
}
// BUTTON LISTENERS
fall.addEventListener(MouseEvent.CLICK, btnClick);
face.addEventListener(MouseEvent.CLICK, btnClick);
rott.addEventListener(MouseEvent.CLICK, btnClick);
angel.addEventListener(MouseEvent.CLICK, btnClick);
ratts.addEventListener(MouseEvent.CLICK, btnClick);
metal.addEventListener(MouseEvent.CLICK, btnClick);
//etc...
//BACK BUTTON
BB3.addEventListener(MouseEvent.CLICK, BB3Click);
function BB3Click(e:MouseEvent):void {
swfLoader.unloadAndStop();
removeChild(swfLoader);
this.gotoAndPlay(1 ,"Scene 2")
}

flash as3 Fadein fadeout xml slideshow

I am new to as3.0 and want to complete my project.
I am using the below code for my xml slideshow but I want the pictures to fade into each other it should never fade to complete white. Hope any expert can help me.
import gs.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import fl.transitions.easing.*;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//hides the description box until the image is loaded
//hides the image until it is loaded
theImage.alpha=0;
loadingBar.visible = false;
//variables to hold the final coordinates of the image tween
var finalX:Number;
var finalY:Number;
//variable to hold the number of images in the XML
var listLength:Number;
//keeps track of what image should be displayed
var currPainting:Number=0;
//arrays to hold the contents of the XML, using this to allow
//for the random order of the images
var imageArray:Array = new Array();
//Loader event for the XML
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);
var xml:XML;
loader.load(new URLRequest("galleries/xml/maingallery.xml"));
function onLoaded(e:Event):void {
//load XML
xml=new XML(e.target.data);
var il:XMLList=xml.images;
listLength=il.length();
populateArray();
}
function populateArray():void {
//takes the properties defined in the XML and stores them
//into arrays
var i:Number;
for (i = 0; i < listLength; i++) {
imageArray[i]=xml.images[i].pic;
}
beginImage();
}
function beginImage():void {
//grabs a random number between 0 and the number
//of images in the array
//load description
var imageLoader = new Loader();
//catches errors if the loader cannot find the URL path
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, catchFunction);
//actually loads the URL defined in the image array
imageLoader.load(new URLRequest(imageArray[currPainting]));
//adds a listener for while the image is loading
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imgLoading);
//adds a listener for what to do when the image is done loading
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function catchFunction(e:IOErrorEvent) {
trace("Bad URL: " + imageArray[currPainting] + " does not exist");
//take out the bad URL from the array
imageArray.splice(currPainting,1);
//check to see if there are images left,
//else restart the slideshow
if (imageArray.length==0) {
populateArray();
} else {
beginImage();
}
}
function imgLoading(event:ProgressEvent):void{
//show the loading bar, and update the width
//based on how much is loaded
loadingBar.visible = true;
loadingBar.bar.scale = (event.bytesLoaded/event.bytesTotal)*100;
loadingBar.x = stage.stageWidth/2;
loadingBar.y = stage.stageHeight - 400;
}
var widthRatio:Number;
var heightRatio:Number;
function imgLoaded(event:Event):void {
loadingBar.visible = false;
//add the image and get the dimensions to center the image
theImage.addChild(imageLoader);
if (imageLoader.width > stage.stageWidth){
widthRatio=imageLoader.width/stage.stageWidth;
trace(widthRatio)
trace(imageLoader.width);
}
if (imageLoader.height > stage.stageHeight - 207){
heightRatio=imageLoader.height/(stage.stageHeight - 207) ;
trace(heightRatio)
trace(imageLoader.height)
}
if (widthRatio > heightRatio){
imageLoader.width = stage.stageWidth;
imageLoader.height = imageLoader.height/widthRatio;
} else {
imageLoader.height = stage.stageHeight - 207;
imageLoader.width = imageLoader.width/heightRatio;
}
imageLoader.x = (imageLoader.stage.stageWidth / 2) - (imageLoader.width / 2);
imageLoader.y = 0
//take the contents of the loaded image and cast it as bitmap data
//to allow for bitmap smoothing
var image:Bitmap = imageLoader.content as Bitmap;
image.smoothing=true;
//start tween function
easeIn();
}
}
function easeIn():void {
TweenLite.to(theImage, 5, {onComplete:hideStuff});
TweenLite.to(theImage, 1, {alpha:1, overwrite:0});
}
function hideStuff():void {
TweenLite.to(theImage, 1, {alpha:0, onComplete:nextImage});
}
function nextImage():void {
//take out the image that was just displayed
imageArray.splice(currPainting,1);
//remove the picture
theImage.removeChildAt(0);
//start over
if (imageArray.length==0) {
populateArray();
} else {
beginImage();
}
}
Ok, first you need to create a variable for the image you wish to fade in. Let's organise it so it is clear which is which.
var theCurrentImage:DisplayObject;
var theNextImage:DisplayObject;
Load in the first image (now theCurrentImage) in the same way as before.
Now here's how you could load in the next image in the array:
function loadNextImage():void {
currPainting++;
// you should also make sure currPainting is not out of bounds here
loadImage();
}
function loadImage():void {
imageLoader = new Loader();
imageLoader.addEventListener(Event.COMPLETE, onImageLoaded);
// other listeners go here too
imageLoader.load(new URLRequest(imageArray[currPainting]));
}
function onImageLoaded(e:Event):void {
theNextImage = imageLoader; // stores the next image ready to be faded in
theNextImage.alpha = 0;
addChild(theNextImage); // now ready to be cross-faded in
crossFade();
}
function crossFade():void {
TweenLite.to(theCurrentImage, 1, {alpha:0});
TweenLite.to(theNextImage, 1, {alpha:1});
// remove theCurrentImage (now invisible) from the stage
removeChild(theCurrentImage);
// theNextImage is now the displayed image so...
theCurrentImage = theNextImage;
theNextImage = null;
// ready to load the next image by calling loadNextImage()
}

unload external swf (child) from the main screen when it has reached last frame?

I have an external swf loading into a main frame (the URL request), and when the swf reaches it's final frame I need it to UNLOAD itself. I need to do this without any code on the CHILD swf, as this is for an iOS application. Can anyone help?
//start button
start_button_aboriginal.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_3);
import fl.display.ProLoader;
var fl_ProLoader_3:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad_3:Boolean = true;
function fl_ClickToLoadUnloadSWF_3(event:MouseEvent):void
{
if(fl_ToLoad_3)
{
fl_ProLoader_3 = new ProLoader();
fl_ProLoader_3.load(new URLRequest("myths/myth_aboriginal.swf"));
addChild(fl_ProLoader_3);
fl_ProLoader_3.x = 114;
fl_ProLoader_3.y = 41;
}
else
{
fl_ProLoader_3.unload();
removeChild(fl_ProLoader_3);
fl_ProLoader_3 = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_3 = !fl_ToLoad_3;
//here, I want to UNLOAD the external SWF when it is finished playing.
var totFrames:Number=childMC.totalFrames;
var curFrame:Number;
childMC.addEventListener(Event.ENTER_FRAME, remove);
function remove(evt:Event):void {
curFrame=childMC.currentFrame;
if (totFrames==curFrame) {
removeChild(childMC);
}
}
You need to declare childMC in a global scope and the assign the loader content.
and dont declare functions inside of functions!!
something like this NOT TESTET
import fl.display.Loader; // impoerts belong at the top
var fl_ProLoader_3:ProLoader; // then your global vars
var childMC:MovieClip; // instatiate childMC with global scope
start_button_aboriginal.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_3,false,0,false); // listener with weak refference
var fl_ToLoad_3:Boolean = true;
function fl_ClickToLoadUnloadSWF_3(event:MouseEvent):void
{
if(fl_ToLoad_3)
{
fl_ProLoader_3 = new Loader();
var url:URLRequest = new URLRequest("myths/myth_aboriginal.swf");
var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null); // IOS needs this
fl_ProLoader_3.load(url, loaderContext);
fl_ProLoader_3.addEventListener(Event.COMPLETE, loadCompleteHandler,false,0,false);
}
else
{
if(childMC){
removeChild(childMC);
childMC.unloadAndStop();
childMC = null;
}
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_3 = !fl_ToLoad_3;
}
function loadCompleteHandler(evt:Event):void
{
childMC = evt.target.content as MovieClip;
childMC.addEventListener(Event.ENTER_FRAME, remove);
addChild(childMC);
childMC.x = 114;
childMC.y = 41;
}
function remove(evt:Event):void {
var totFrames:Number=childMC.totalFrames;
var curFrame:Number =childMC.currentFrame;;
if (totFrames==curFrame) {
childMC.removeEventListener(Event.ENTER_FRAME, remove);
removeChild(childMC);
childMC.unloadAndStop();
childMC = null;
}
}

action script 3.0 .I had tried a program that should move the dragger as well as the content movieclip,

In this code i need a progressbar to progress through while the imported .swf file is playing, meanwhile i should able to drag the dragger in the progress bar (i.e the rate of movement of dragger should sync with rate of .swf file playing). I got Argument error: #2109 Frame label 459.99 not found in scene1.
var loader:Loader = new Loader();
playBtn.visible = true;
pauseBtn.visible = false;
btn_00.addEventListener(MouseEvent.CLICK, fileLoaded);
btn_01.addEventListener(MouseEvent.CLICK, fileLoaded);
btn_02.addEventListener(MouseEvent.CLICK, fileLoaded);
function fileLoaded(evt:MouseEvent):void
{
var fileName:String = evt.currentTarget.name;
var fileNumber:String = fileName.split("_")[1];
var urlPath:String = "assets/file_" + fileNumber + ".swf";
loader.load(new URLRequest(urlPath));
addChild(loader);
}
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
function swfLoaded(event:Event):void
{
addEventListener(Event.ENTER_FRAME, trackPlayback);
}
function trackPlayback(event:Event):void
{
var perPlayed:Number = MovieClip(loader.content).currentFrame / MovieClip(loader.content).totalFrames;
progressbar.drag.x = (progressbar.bar.width - progressbar.drag.width) * perPlayed;
}
progressbar.drag.buttonMode = true;
var dragClicked:Boolean = false;
var xpos:Number = progressbar.bar.x * progressbar.drag.width;
progressbar.drag.addEventListener(MouseEvent.MOUSE_DOWN,dragMouseDown);
function dragMouseDown(evt:MouseEvent):void
{
trace(" inside mouse down ");
dragClicked = true;
progressbar.drag.startDrag(false,new Rectangle(xpos,0,progressbar.width-progressbar.drag.width,0));
}
progressbar.drag.addEventListener(MouseEvent.MOUSE_UP,dragMouseUp);
function dragMouseUp(evt:MouseEvent):void
{
dragClicked = false;
progressbar.drag.stopDrag();
var cnt:Number = (progressbar.drag.x/(progressbar.width-progressbar.drag.width))*MovieClip(loader.content).totalFrames;
MovieClip(loader.content).gotoAndPlay(cnt);
}
Pls solve my issue.
Thanks in advance.
To access a specific frame, you need to provide an integer value where at the moment you are using a floating-point value.
A simple fix would be to cast the Number to an int:
MovieClip(loader.content).gotoAndPlay(int(cnt));

Flash As3 Loader Problem

Hi iam trying to load a few external jpegs in As3.
It works fine locally in Flash, but it dosen't work at all ion my server.
My app also loads a youtube video simultaneously.
function drawResult(index,videoID,song_title,thumbnail:String=null)
{
var theClip:resultRowClip=new resultRowClip ();
_clip.addChild(theClip);
myArray[index] = new Array(videoID,theClip);
theClip.y=0+(43*(index-1));
theClip.rowText.text = song_title;
theClip.rowBack.visible = false;
if (thumbnail != ""){
theClip.tHolder.visible=true;
loadImage(thumbnail,index);
}
}
function loadImage(url:String,index):void
{
//this.myClip.myText.text += "load image";
// Set properties on my Loader object
var imageLoader:Loader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (evt:Event){imageLoaded(evt,index)});
}
function imageLoaded(evt,id):void
{
//this.myClip.myText.text += "id : evt : " + evt.status;
// Load Image
var image:Bitmap = new Bitmap(evt.target.content.bitmapData);
myArray[id][1].tHolder.addChild(image);
myArray[id][1].tHolder.width=myArray[id][1].tHolder.width*0.35;
myArray[id][1].tHolder.height=myArray[id][1].tHolder.height*0.35;
}
Does anyone knows what the problem is ?
** I added two Evenet listeners from io Error :
imageLoader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
This is the function for handling the errors :
private function ioErrorHandler(event:IOErrorEvent):void {
this.myClip.myText.text +=("ioErrorHandler: " + event);
}
anyway, I got no errors...
I also tried to move the listeners before imageLoader.load but it's still the same...no errors and no data loaded..
I change my code to patrikS suggestion :
function loadImage(url:String,index):void
{
//this.myClip.myText.text += "load image";
// Set properties on my Loader object
//if (index != 1) return;
var imageLoader:Loader = new Loader();
imageLoader.name = index.toString();
//myArray[index][1].addChild(imageLoader);
//imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (evt:Event){imageLoaded(evt,index)});
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
imageLoader.load(new URLRequest(url));
}
My current completeHandler function(tnx patrikS ) :
private function completeHandler(evt:Event):void{
//this.myClip.myText.text += "id : evt : " + evt.status;
// Load Image
trace("evt target loader name : "+ evt.target.loader.name );
evt.target.removeEventListener(Event.COMPLETE, completeHandler );
var image:Bitmap = new Bitmap(evt.target.content.bitmapData);
myArray[evt.target.loader.name][1].tHolder.addChild(image);
myArray[evt.target.loader.name][1].tHolder.width=myArray[evt.target.loader.name][1].tHolder.width*0.35;
myArray[evt.target.loader.name][1].tHolder.height=myArray[evt.target.loader.name][1].tHolder.height*0.35;
//trace (hadar.y + "Y / X" + hadar.x);
}
It still work only on flash IDE and dosent work on any browser...
try urlstream and check crossdomain.xml :)
urlstream = new URLStream();
urlstream.addEventListener(Event.COMPLETE, onLoad);
urlstream.addEventListener(IOErrorEvent.IO_ERROR, onErr);
urlstream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onErr);
urlstream.load(req);
private function onLoad(e:Event):void {
var ba:ByteArray = new ByteArray();
urlstream.readBytes(ba, 0, urlstream.bytesAvailable);
_loader.contentLoaderInfo.addEventListener(Event.INIT, onBytesLoad);
_loader.loadBytes(ba);
}
Listeners should be added before calling the load() method.
Also there's no real advantage in using a closure for the complete event listener & think of removing the event listeners!
function loadImage(url:String, index:int):void
{
//this.myClip.myText.text += "load image";
// Set properties on my Loader object
var imageLoader:Loader = new Loader();
imageLoader.name = index.toString();
//make sure you to add your listeners here!
imageLoader.contentLoaderInfo.addEventListener(
IOErrorEvent.IO_ERROR,ioErrorHandler);
imageLoader.contentLoaderInfo.addEventListener(
Event.COMPLETE, completeHandler );
imageLoader.load(new URLRequest(url));
}
function completeHandler(event:Event ):void
{
//imageLoaded(evt,index);
trace( event.target.loader.name );
event.target.removeEventListener(Event.COMPLETE, completeHandler );
}
In debug model, you can load files from any avaliable site, but release model.
may be this help : http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html