on press if currentframe ==
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: on press if currentframe ==

  1. #1
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    733

    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
    stackoverflow allows forky for four key as the stack exchange

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,687
    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
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    733
    Thanks, glad to see that as3 does use currentFrame
    stackoverflow allows forky for four key as the stack exchange

  4. #4
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    733
    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
    stackoverflow allows forky for four key as the stack exchange

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,687
    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
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    733
    Thanks! works like magic, are you a wizard?
    stackoverflow allows forky for four key as the stack exchange

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

  8. #8
    Senior Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    733
    xD
    stackoverflow allows forky for four key as the stack exchange

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

Poll by Flashkit.com