Skip to main content
Known Participant
September 29, 2010
Question

Type coercion error

  • September 29, 2010
  • 1 reply
  • 542 views

This is from another thread that I marked fixed but I still have an issue, so I thought I would start a new post.

I'm loading images from xml into an array of movieClips.  I'm almost there thanks to a bunch of your responses.

I'm getting a type coercion error that I traced down to this line:

mainClipArray[counter].addChild(e.target);

It doesn't seem to like the e.target.  Anyone see the error?

CODE:

var myXML:XML;
var xmlLoader:URLLoader = new URLLoader();
var mainClipArray:Array = [];
var counter:int = 0;

xmlLoader.load(new URLRequest("portfolio.xml"));
xmlLoader.addEventListener(Event.COMPLETE, completeXMLLoad);

function completeXMLLoad(e:Event):void{
    myXML = XML(e.target.data);
    var len:int = myXML.portfolio.unit.length();
    loadMainImage();
}

function loadMainImage(){
    var myLoader:Loader = new Loader();
    var smallfilename = myXML.portfolio.unit[counter].small.filename;
    myLoader.load(new URLRequest(smallfilename));
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeClipLoad);
}

function completeClipLoad(e:Event):void{
    mainClipArray[counter] = new pane();
    mainClipArray[counter].addChild(e.target);
    addChild(mainClipArray[counter]);
    mainClipArray[counter].x = counter * 15;
    mainClipArray[counter].y = 320 - mainClipArray[counter].height;
    counter ++;
    if(counter < myXML.portfolio.unit.length()){
        loadMainImage();
    } else {
        layoutImages();
    }
}

function layoutImages(){
   
}

This topic has been closed for replies.

1 reply

Inspiring
September 29, 2010

This code is more efficient and it should fix the error:

var p:pane = new pane();
p.addChild(DisplayObject(e.target));
addChild(p);
p.x = counter * 15;
p.y = 320 - p.height;
mainClipArray[counter] = p;

coolyodaAuthor
Known Participant
September 29, 2010

I really need p to remain an array of movie clips class pane. But I tried adding DisplayObject to my addChild.

mainClipArray[counter].addChild(DisplayObject(e.target));

Still getting a type coercion.

Inspiring
September 29, 2010

It does remain a member of the array because mainClipArray[counter] = p;