Hi, guys.
I need some help on this subject:
var arr:Array = new Array();
// quad 1:
var quad1:Sprite = new Sprite();
quad1.name = "green_mc";
quad1.graphics.beginFill(0x00ff00);
quad1.graphics.drawRect(-15,-15,30,30);
quad1.addEventListener(MouseEvent.CLICK, quadClick);
quad1.x = quad1.y = 100;
arr.push(quad1);
addChild(quad1);
// quad 2:
var quad2:Sprite = new Sprite();
quad2.name = "red_mc";
quad2.graphics.beginFill(0xff0000);
quad2.graphics.drawRect(-15,-15,30,30);
quad2.addEventListener(MouseEvent.CLICK, quadClick);
quad2.x = 200;
quad2.y = 100;
arr.push(quad2);
addChild(quad2);
// function wich handle the CLICK event:
function quadClick(evt:MouseEvent):void {
** trace(evt.currentTarget.name);
trace(evt.currentTarget == arr[0]);
trace(evt.currentTarget == quad1);**
trace("=====x======");
var actualQuad = evt.currentTarget;
actualQuad.filters = [ new DropShadowFilter() ];
actualQuad.scaleX = actualQuad.scaleY += .10;
setChildIndex(actualQuad, numChildren -1);
}
Well. Here I´ve created 2 Sprites, put it into an Array and add it to stage.
Ok. When I click it, it calls the method “quadClick”. The first three lines says:
- The instance name of the Sprite.
- Make a comparison to know if the sprite clicked is the first or the second Sprite into the array previously populated.
- Check if the evt.currentTarget is the “quad1” Sprite, hard-coded.
Well. It works fine.
Then is the annoyng problem: When I use a variable to store the actual Sprite, like “actualQuad”, it does not accept the Sprite data type, dispite all the traces above. It just accept the DisplayObject data type. Why this happen? If I flash output the event.currentTarget like a “[object Sprite]”, why, after all, it thinks that is a DisplayObject and not a Sprite?
Are they the same thing? Is a Sprite a “extended” class of DisplayObject and, if so, why I need to use the SuperClass data type? I lost some “especial” property of Sprite Class on this way?
Wow. I’m speaking too much. Could some one explain the differences between them?
Thanks a lot.
pp
PS:
What I´m trying to do is, on AS 2.0, the old “attachMovie” on a looping like this:
for (var i:Number = 0; i < 10; i++) {
[COLOR=Red] // attach the movieClip:[/COLOR]
content_mc.attachMovie("linkage", "mc" + i, i);
**[COLOR=Red]// point a variable for quick access to the clip attached:[/COLOR]**
**var movie:MovieClip = content_mc["mc" + i];**
[COLOR=Black][COLOR=Red]
// then I can just write like[/COLOR]
movie._x = 10 * i;
[COLOR=Red]// instead of:[/COLOR]
content_mc["mc" + i]._y = 20;[/COLOR]
}