Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

dynamic menu in AS3

New Here ,
Jan 08, 2014 Jan 08, 2014

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

TOPICS
ActionScript
867
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 08, 2014 Jan 08, 2014

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

...
Translate
LEGEND ,
Jan 08, 2014 Jan 08, 2014

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)
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2014 Jan 08, 2014

Thank you,
but there is a problem,
I have one Boton in a library

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 10, 2014 Jan 10, 2014

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);

   

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2014 Jan 10, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2014 Jan 11, 2014
LATEST

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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines