A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Newbie question

  1. #1
    MindGem Graphics Inc. JediMind's Avatar
    Join Date
    Nov 2001
    Location
    Stockholm/Sweden
    Posts
    407

    Newbie question

    So I have a button on which I create an instance of a symbol,
    I'd like to have a listener for the new symbol but I get a reference error because it compiles the listener before I get to create the instance.
    What do I do?

    button1.addEventListener(MouseEvent.CLICK, test);
    function test(e:MouseEvent):void
    {
    var ball:Ball = new Ball();
    addChild(ball);
    }

    ball.addEventListener(MouseEvent.CLICK, test2);
    function test2(e:MouseEvent):void
    {
    trace("test");
    }

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Try this

    Actionscript Code:
    button1.addEventListener(MouseEvent.CLICK, test);
    function test(e:MouseEvent):void
    {
      var ball:Ball = new Ball();
       ball.addEventListener(MouseEvent.CLICK, test2);
       addChild(ball);
    }


    function test2(e:MouseEvent):void
    {
     trace("test");
    }

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