A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: on press if currentframe ==

  1. #1
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404

    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

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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

  3. #3
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Thanks, glad to see that as3 does use currentFrame

  4. #4
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    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

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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 0py <rowspy++)
    {
        for (var 
    px:int 0px <colspx++)
        {
            var 
    grid:Grid = new Grid();
            
    grid.300 grid.width px;
            
    grid.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);
        }


  6. #6
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Thanks! works like magic, are you a wizard?

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    No, but I put a spell on you

  8. #8
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    xD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center