I have a red box called mc1_mc and every time when you drag on it you get a new little blue box added to the stage. Yhe idea is that you can drag those blue boxes too. however I dont know how to detect them.
this is the code:
var newBlok:Boolean;
var blokIndex:int = 0;
var blokje:blok;
var huidigBlok:DisplayObject;
var prullenBak:DisplayObject = getChildByName("groen_mc");
stage.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);
function pickUp(event:MouseEvent):void
{
trace(event.currentTarget);
trace(event.target);
trace(event.target.name);
if (event.target.name == "mc1_mc")
{
trace("hoi");
blokje = new blok;
blokje.name = "blokje" + blokIndex;
blokIndex++;
addChild(blokje);
blokje.startDrag(true);
}
if (event.target.type == blok)
{
trace("blok");
}
//blokjeVast = blokje;
}
function dropIt(event:MouseEvent):void
{
event.target.stopDrag();
}
he wont ever come to the line: trace(“blok”);
even when the object i clicked on gives:
[object Stage]
[object blok]
blokje0
for the lines.
trace(event.currentTarget);
trace(event.target);
trace(event.target.name);
does anyone know how to do check if its a object of type “blok”?
To check whether an object is of a certain type, you can use the is operator.
So, you should change this:
To this:
And if the target is of type blok, you should see the trace.
There’s one caveat here.
ìstells you if an object is of a certain type. Since a class can extend other classes and implement interfaces, you should check for the most derived or specific one first (if you want to distinguish between, say, Sprite and MovieClip).