-
Client Software Programmer
on press if currentframe ==
can someone convert this as2 code to as3
square.onPress = function(){
if(_root.thing1._currentframe == 2){
_root.square.gotoAndStop(3);
}
plz and Thanks, I suck at as3, please leave comments in the code to help me out if you can
-
.
Hi,
The code speaks for itself alloy, try
PHP Code:
import flash.events.MouseEvent;
square.addEventListener(MouseEvent.CLICK,doFunction);
square.buttonMode = true;
function doFunction(e:MouseEvent):void
{
trace(e.currentTarget.name);
if (MovieClip(root).thing1.currentFrame == 2)
{
e.currentTarget.gotoAndStop(3);
}
}
for button events (and other things) we add an eventListener
e = event that has been called/being used
e.currentTarget = the button using the event (in this case)
thats the best I can do quickly
-
Client Software Programmer
Thanks, glad to see that as3 does use currentFrame
-
Client Software Programmer
im getting runtime errors import flash.events.MouseEvent;
Grid.addEventListener(MouseEvent.CLICK,doFunction) ;
Grid.buttonMode = true;
function doFunction(e:MouseEvent):void
{
trace(e.currentTarget.name);
if (MovieClip(root).color_red.currentFrame == 2)
{
e.currentTarget.gotoAndStop(2);
}
}
var rows:int = 10;
var cols:int = 10;
for(var py:int = 0; py <rows; py++){
for(var px:int = 0; px <cols; px++){
var grid:Grid = new Grid();
grid.x = 300 + grid.width * px;
grid.y = 100 + grid.height * py;
addChild(grid);
}
}
do you know what i did wrong, im trying to make the grid clickable in my array
-
.
Hi,
Without seeing your set up I belive this will help, as you can see you were adding the mouseevent before adding or declaring the movies
PHP Code:
import flash.events.MouseEvent;
var rows:int = 10;
var cols:int = 10;
for (var py:int = 0; py <rows; py++)
{
for (var px:int = 0; px <cols; px++)
{
var grid:Grid = new Grid();
grid.x = 300 + grid.width * px;
grid.y = 100 + grid.height * py;
grid.addEventListener(MouseEvent.CLICK,doFunction);
grid.buttonMode = true;
addChild(grid);
}
}
function doFunction(e:MouseEvent):void
{
trace(e.currentTarget);
trace(MovieClip(root).color_red.currentFrame);
if (MovieClip(root).color_red.currentFrame == 2)
{
e.currentTarget.gotoAndStop(2);
}
}
-
Client Software Programmer
Thanks! works like magic, are you a wizard?
-
.
No, but I put a spell on you
-
Client Software Programmer
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
|