-
Designer, Programmer, Musician
Multiple Movieclips Press
Hello guys, i am from the AS2 forum, now i'm introducing myself to AS3 to develop android apps
So, I already achieved few things, Depths, addChild, listeners, etc. but now i'm stucked in something I do very well in AS2, it would be something like this:
PHP Code:
var Amount:Number = 5;
for (i = 0; i < Amount; i++)
{
adder = i + 1;
this["mc" + adder].Num = i;
this["mc" + adder]._x = i * (this["mc" + adder]._width + 2);
this["mc" + adder]._y = 200;
this["mc" + adder].onPress = function()
{
trace(this.Num);
}
}
I tried this on AS3, and searched on google and in this forum and no answers:
PHP Code:
var Num:Number;
var Amount:Number = 5;
var mc:mclip;
for (var i:Number = 0; i < Amount; i++)
{
var adder:Number = i + 1;
mc = new mclip();
addChild(mc);
mc.name = "mc"+ adder;
mc.x = i * (mc.width + 2);
mc.y = 200;
mc.Num = adder;
mc.addEventListener(MouseEvent.MOUSE_DOWN, Press);
function Press (e:MouseEvent):void
{
trace(this.Num);
}
}
I achieved creating the 5 movieclips, and they all respond to the press, but all of them throws the Num variable "5" , the last "i" number of the for loop, and they are supposed to thow their corresponding number (mc1 = 1, mc2 = 2, etc)
What am I missing? I have like 3 as3 pdf books and no explanation in this specific scenario. Thanks
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
I assume you have 5 clips on the stage named mc1, mc2, mc3, mc4, mc5
You can not change the name of a time line placed clip by the way.
so mc.name = "mc"+ adder; would have thrown errors to see to start with.
Maybe this will help you along
PHP Code:
import flash.display.*;
import flash.events.*;
var Num:Number;
var Amount:Number = 5;
var ClipArray:Array = [mc1,mc2,mc3,mc4,mc5];
for (var i:Number = 0; i < Amount; i++)
{
var Mc:MovieClip = ClipArray[i];
Mc.Num = i + 1;
Mc.x = i * (ClipArray[i].width + 2);
Mc.y = 200;
Mc.buttonMode = true;
Mc.addEventListener(MouseEvent.MOUSE_DOWN, Press);
}
function Press(event:MouseEvent):void
{
var mc:MovieClip = MovieClip(event.currentTarget);
trace("Num = " + event.currentTarget.Num + ". Name = " + event.currentTarget.name);
//addChild(mc);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|