Scorp-D
12-05-2007, 08:31 AM
I’m used to Java, but wanted to try Actionscript, because my teacher told me that it was an exciting language to work in.
So I made an Actionscript 2.0 game, which only took a couple of hours to make.
BUT now I’m trying to convert it into Actionscript 3.0, so far I have used a couple of days, and have found a problem that I can’t seem to solve.
Question:
I used hitTest() in Actionscript 2.0 to check if a element was above one of 25 other elements, and the underlying element should go to its own frame 2.
I have read that it might be possible to use getBounds () on a movieclip, which returns a rectangle, that can be used in containsRect(), but I haven’t found any examples that contrasts what I’m doing.
I have created the following code in Actionscript 3.0 which works until the ’gotoandstop’ call (placed in an .as file).
public function ButtonUp(event:MouseEvent):void
{
for(var i =1;i<=25 ;i++)
{
var myTargetName1:String = "element" + i;
var myTarget1: DisplayObject = getChildByName(myTargetName1);
if(event.target.dropTarget != null && event.target.dropTarget.parent == myTarget1)
{
myTarget1.gotoAndStop(2);
break;
}
}
}
This is the Actionscript 2.0 code that I’m trying to convert (code is placed in the frame of which the elements are, and ):
function checkTarget(drag)
{
for(i =0;i<=25 ;i++)
{
if(drag.hitTest(_root["element"+i]))
{
tellTarget(_root["element"+i])
{
gotoAndStop(2);
}
}
}
}
Code is executed by:
elementRemover.onPress = function()
{
checkTarget(this);
}
Scorp-D
So I made an Actionscript 2.0 game, which only took a couple of hours to make.
BUT now I’m trying to convert it into Actionscript 3.0, so far I have used a couple of days, and have found a problem that I can’t seem to solve.
Question:
I used hitTest() in Actionscript 2.0 to check if a element was above one of 25 other elements, and the underlying element should go to its own frame 2.
I have read that it might be possible to use getBounds () on a movieclip, which returns a rectangle, that can be used in containsRect(), but I haven’t found any examples that contrasts what I’m doing.
I have created the following code in Actionscript 3.0 which works until the ’gotoandstop’ call (placed in an .as file).
public function ButtonUp(event:MouseEvent):void
{
for(var i =1;i<=25 ;i++)
{
var myTargetName1:String = "element" + i;
var myTarget1: DisplayObject = getChildByName(myTargetName1);
if(event.target.dropTarget != null && event.target.dropTarget.parent == myTarget1)
{
myTarget1.gotoAndStop(2);
break;
}
}
}
This is the Actionscript 2.0 code that I’m trying to convert (code is placed in the frame of which the elements are, and ):
function checkTarget(drag)
{
for(i =0;i<=25 ;i++)
{
if(drag.hitTest(_root["element"+i]))
{
tellTarget(_root["element"+i])
{
gotoAndStop(2);
}
}
}
}
Code is executed by:
elementRemover.onPress = function()
{
checkTarget(this);
}
Scorp-D