PDA

View Full Version : instance Name wrong ...


boomshanka
06-12-2008, 12:54 AM
hello

I'm trying to dropTarget a MC onto another MC ... both with instance names ... but when i trace(event.target.dropTarget.name); i get a name of "instance 132" .

why is it not using the instance name i setup on the stage ?

:confused:

lordofduct
06-12-2008, 12:57 AM
is the dropTarget a container that contains other objects with out instance names?

boomshanka
06-12-2008, 01:00 AM
no... it just contains a regular rectangle 'shape' .

lordofduct
06-12-2008, 02:15 AM
yep, that rectangle shape is the instance you're tracing the name of.

lordofduct
06-12-2008, 02:19 AM
watch, draw two symbols in your library.

One is MC with a small rect, the other is a MC with a large Rect.
put the large rect on the left of the screen, the small rect in the middle of the screen, and on the actionPanel write this:

(don't forget to give them instance names, in my case dragger is the small rect)


dragger.addEventListener(MouseEvent.MOUSE_DOWN, startTheDrag);

var spr:Sprite = new Sprite();
spr.name = "hello world";
var gr:Graphics = spr.graphics;
gr.beginFill(0x000000);
gr.drawRect(0,0, 500, 500);
gr.endFill();
spr.x = 300;
addChildAt(spr, 0);

function startTheDrag(e:MouseEvent):void
{
dragger.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, stopTheDrag);
}

function stopTheDrag(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, stopTheDrag);
dragger.stopDrag();
trace(e.target.dropTarget.name);
}


note the black rect on the right traces the name because you drew directly to it's graphics layer which isn't a DisplayObject perse. But the large rect on the left traces an instance name because you dropped onto a Shape inside of a MovieClip, that shape is a DisplayObject.

boomshanka
06-12-2008, 03:09 AM
wow ... thanks for your help lordofduct .

it makes sense why its not working now - tho' i'm not liking it .

i guess a work around is to create an alpha=0 shape on top of the MC target with the desired target name ... would that be the best way ?

boomshanka
06-12-2008, 10:40 PM
ok ... everything has an instance name it seems ... and in this case i should have been targeting the parent instead of the child using event.target.dropTarget.parent.name as the MC receiving the drop .

ok . phew .