Hi all,
it’s been a long time since I’ve posted here! Hope everyone is well.
I am in need of some advice, my AS skills dwindled away when AS 2.0 came in and I am trying to get up to speed on AS3.
I am trying to dynamically create a number of click buttons based on the content of an XML file.
So I have a MC (window_mc) which contains a single button (more_details_btn). I add an event listener to send the user to a web page on click.
However. On some items I need more than 1 more_details_btn’s. What is the best way to duplicate this MC and assign a new click event and different text.
Below is the code I am currently using and it is causing me all sorts of problems
for each(var detail:XML in productXML.details) {
var btn = new more_btn_cls();
btn.label_txt.text = detail.@name;
btn.x = 100;
btn.y = 200;
window_mc.addChild(btn);
}
Firstly, it wont assign btn.label.text - it says it “Cannot access a property or method of a null object reference” btn in this code traces as an object not a movieclip is that why?
The other problem is that window_mc.addChild(btn); does nothing, yet if I take away window_mc it does add the clips to the Stage. (I need them inside window_mc though)
OK, I hope that made sense, and I hope someone can help. I can’t wait to get to grips with AS3 properly - I’m writing really bad code at the moment =)
Thank you!