Can Flash AS3 listbox data contain variable info?
I'm populating a listbox like this:
dp.addItem( {label:"red dress", data:"OV4MP/23OL.swf"} );
Instead of data:"OV4MP/23OL.swf", I would like to make part of the data file name a variable from a dynamic textbox named centerPt that belongs to the parent movieclip, so I did this:
dp.addItem( {label:"red dress", data:"OV4MP/23"+MovieClip(parent.parent).centerPt.text+".swf"} );
When I trace the selectedItem.d开发者_StackOverflow社区ata using: trace("you have selected: "+ overlays.selectedItem.data); trace(MovieClip(parent.parent).centerPt.text); I'm getting: you have selected: OV4MP/23.swf. What I should get is OV4MP/23OL.swf. It is not picking up what is in the dynamic centerPt.text field which are the letters OL eventhough that text field is tracing correctly.
Is it possible that data can not hold a variable?
Thank you in advance for any help.
Anne
Instead of trying to use a variable in the array data of listbox, ie
dp.addItem( {label:"red dress", data:"chp"+MovieClip(parent.parent).centerPt.text+".swf"} );
I used a function in the CHANGE event to return the variable called theOverlay and included the label from the listbox (also now loading .png file instead of .swf):
dp.addItem( {label:"red dress"} );
var theOverlay:String;
var myLoader:Loader = new Loader();
myListbox.addEventListener(Event.CHANGE, getIt);
function getIt(e:Event):void {
theOverlay = "chp/"+myListbox.selectedItem.label+MovieClip(parent.parent).centerPt.text+".png";
var myRequest:URLRequest = new URLRequest(theOverlay);
myLoader.load(myRequest);
}
精彩评论