Beating my head against the wall on this one. A personal project to sharpen my skills in the down time. I’m an ActionScript 2.0 guy, so this ActionScript 3.0 jazz is killing my gray matter.
I am trying to generate a list of clickable items. The titles are being pulled in from an external XML. The function successfully adds and removes clips and brings in the titles accordingly. But “addEventHandler” seems to have no effect. Is it possible to add an event handler to a dynamically created object in this manner?
Everything else works fine (or well enough); it’s the code in red that is not doing anything. What am I doing wrong?
function popVideo():void {
// POPULATE VIDEO LIST
if (listArray.length > 0) {
for each (var lister:clipTitle in listArray) {
trace(lister +" "+ lister.name);
mediaList.removeChild(lister);
}
}
listArray.length = 0;
var lastY:Number = 5;
counter = 0;
var vidXML:XMLList = animeXML.anime[currTopic].videos.clip; // <clip titl="Test Video XX" loc="" scrn="" />
for each (var vid:XML in vidXML) {
counter++;
var nextVid:clipTitle = new clipTitle();
mediaList.addChild(nextVid);
nextVid.x = 15;
nextVid.y = lastY + 25;
lastY += 25;
nextVid.name = "vidClip" + counter;
nextVid.vidname.text = vid.attribute("titl");
listArray.push(nextVid);
listArray[counter - 1].name = "vidClip" + counter;
// This works elsewhere in my AS to turn a movie clip into a button; why not now??
[COLOR=#ff0000] nextVid.buttonMode = true;
nextVid.useHandCursor = true;
nextVid.addEventListener(MouseEvent.CLICK, function(e:Event):void {
var vid:Object = e.currentTarget;
trace("Does it work yet?! " + nextVid.vidname.text)
});[/COLOR]
}
mediaList.y = 50; // Temporary
}