Flash As3 Loader Problem

Posted by Hadar on Stack Overflow See other posts from Stack Overflow or by Hadar
Published on 2010-10-18T08:16:20Z Indexed on 2012/09/15 15:38 UTC
Read the original article Hit count: 207

Filed under:
|

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...

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about loader