A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: [RESOLVED] How to add key listener to the stage

  1. #21
    Member
    Join Date
    Mar 2009
    Posts
    62
    thank you times a million though for your help

  2. #22
    Member
    Join Date
    Mar 2009
    Posts
    62
    What I don't understand still though is, whilst my code works by only adding the keyEvent handlers once this has been added to the display list, if I call that same listener function (taking out the e:Event parameter) from the constructor function to get it to set up the keylisteners, it says that null message again. Surely it should have added it to the stage by 5 lines down the constructor function?

  3. #23
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Nope. The item cannot be added until it is constructed, and it is not finished being constructed until the constructor returns. So the parent and stage will be null through the entire constructor.

  4. #24
    Member
    Join Date
    Mar 2009
    Posts
    62
    Ahhhhh I seeeeeee. So if there's a function in the constructor function that says addEvent() and it goes off to do that, it hasn't completed constructing yet, so the parent and stage are null until it reads and processes the last line in the constructor function?

  5. #25
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Correct. Actually even a little after that, since the execution stack has to be restored and the new object placed on the displaylist.

  6. #26
    Member
    Join Date
    Mar 2009
    Posts
    62
    Quote Originally Posted by 5TonsOfFlax View Post
    Correct. Actually even a little after that, since the execution stack has to be restored and the new object placed on the displaylist.
    Thank you. That's a valuable bit of knowledge I have gained through the last 4 hours of nothing to show for work! That's great, it will no doubt help me structure things better and avoid future similar problems.

  7. #27
    Senior Member
    Join Date
    May 2004
    Posts
    226
    Quote Originally Posted by 5TonsOfFlax View Post
    Could you give an example of some non-keyboard event that you'd want to listen for at the stage level?
    I didn't want to hijack the OP's thread so I started a new one:
    http://board.flashkit.com/board/show...87#post4238887

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