Copy link to clipboard
Copied
I would like to create in AS3, something like, it's in AS2
//_root
var menuArray:Array=new Array("menu0","menu1","menu2","menu3","menu4","menu5");
var gap:Number=10;
var xmenu:Number=10;
for (var i:Number=0;i<menuArray.length;i++){
this.attachMovie("menu_bot", "menu"+i, this.getNextHighestDepth(), {_x:xmenu, _y:100});
xmenu=xmenu+this["menu"+i]._width+gap;
this["menu"+i].num=i;
}
//menu_bot
var num:Number;
textM.text=_root.menuArray[num];
this.onPress=function(){
trace(num);
}
www.4x4nz.sk/downloaded /dinamikmenuas2.fla
The AS3 code would be something along the lines of...
var menuArray:Array=new Array("menu0","menu1","menu2","menu3","menu4","menu5");
var gap:Number=10;
var xmenu:Number=10;
for (var i:Number=0;i<menuArray.length;i++){
var ClassRef:Class = Class(getDefinitionByName("menu"+i));
var classInstance:* = new ClassRef();
classInstance.x = xmenu;
classInstance.y = 100;
addChild(classInstance);
xmenu=xmenu+classInstance.width+gap;
classInstance.num=i;
classInstance.addEventListener(Mou
Copy link to clipboard
Copied
The AS3 code would be something along the lines of...
var menuArray:Array=new Array("menu0","menu1","menu2","menu3","menu4","menu5");
var gap:Number=10;
var xmenu:Number=10;
for (var i:Number=0;i<menuArray.length;i++){
var ClassRef:Class = Class(getDefinitionByName("menu"+i));
var classInstance:* = new ClassRef();
classInstance.x = xmenu;
classInstance.y = 100;
addChild(classInstance);
xmenu=xmenu+classInstance.width+gap;
classInstance.num=i;
classInstance.addEventListener(MouseEvent.CLICK, traceNum);
}
function traceNum(evt:MouseEvent):void {
trace(evt.currentTarget.num)
}
Copy link to clipboard
Copied
Thank you,
but there is a problem,
I have one Boton in a library
Copy link to clipboard
Copied
I found this solution it
does not seem to me to be the most professional, but it works
var Path = this;
var Array_menu:Array=new Array("menu0","menu1","menu2","menu3","menu4","menu5");
var Array_Class:Array = [];
for (var i:Number=0;i<Array_menu.length;i++){
Array_Class.push(Menu_bot);
}
var gap:Number=10;
var xmenu:Number=10;
for (var j:Number=0;j<Array_Class.length;j++)
{
var ClassRef : Object = Array_Class
var classInstance : * = new ClassRef();
classInstance.x = xmenu;
classInstance.y = 100;
Path.addChild(classInstance);
classInstance.num = new Number(j);
classInstance.addEventListener(MouseEvent.MOUSE_DOWN, tracek);
xmenu+= classInstance.width + gap;
}
function tracek(e:MouseEvent) : void
{
trace(e.currentTarget.num);
}
Copy link to clipboard
Copied
If you only have one button symbol you did not need to do alot of what you have done.
Your initial posting asked how to code the AS2 version as AS3 and that is what I provided. If what you asked to have translated does not meet your design needs that is a different matter unrelated to your posting.
Copy link to clipboard
Copied
well you understood me, I want an alternative to the script what I put in AS2,
but I think. of the script as you sent me centenary assume that I have in the library button menu0 menu1 .....
But I have only one menu button.
because I tried it and it did not work.
var ClassRef: Class = Class (getDefinitionByName ("menu" + i));
I will be happy if later you look again
Find more inspiration, events, and resources on the new Adobe Community
Explore Now