Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignFlash Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 23rd, 2011, 03:59 PM
ahillecke ahillecke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 27 ahillecke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 14 sec
Reputation Power: 0
ActionScript 3 - Add EventListener on return to 1st frame

I'm not sure exactly what's going on here (maybe I'm not understanding how the timeline executes?).

I have a game that has the menu in the first frame, the game in later frames. When the game is won, the user is able to click to return to the menu. Using trace(), I've found that the click reads, and it starts to execute the actions that have been written in the 1st frame. But, when it gets to the line that adds an event listener to a button on the stage using solo.addEventListener(MouseEvent.CLICK,goSolo) (solo is the name of the button on the screen), it returns:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

The line executes just fine when the whole thing initializes, so I don't know why it's not working when it restarts. Is the code getting read before the stage is populating when I return the user to the main menu using gotoAndPlay(1) from the click listener? It doesn't make a difference if I use gotoAndStop(1). What's a good workaround?

Or is it because the button is in a layer lower than the actions? (I've always put my actions in the highest layer, and don't remember ever having this problem before). But why then would it still work at the very beginning but not with the restart?

Thanks for any suggestions.

Last edited by ahillecke : May 25th, 2011 at 04:41 PM. Reason: discovered more specific root problem

Reply With Quote
  #2  
Old May 23rd, 2011, 04:44 PM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 6,663 Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)  Folding Points: 14767 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 3 Days 20 h 9 m 42 sec
Reputation Power: 3163
Facebook MySpace
Hi, it doesn't matter which layer you put your code on. Try tracing solo and the actual function to see if they both still exist:

trace("Solo:", solo);
trace("goSolo:", goSolo);
__________________
Quis custodiet ipsos custodes?

Reply With Quote
  #3  
Old May 23rd, 2011, 04:56 PM
ahillecke ahillecke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 27 ahillecke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 14 sec
Reputation Power: 0
this is what it returns when I trace that way:

solo: null
goSolo: function Function() {}

Any idea why solo would become null after gotoAndPlay(1)? When the movie initially goes, it traces (correctly):

solo: [object SimpleButton]
goSolo: function Function() {}

Reply With Quote
  #4  
Old May 23rd, 2011, 05:53 PM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 6,663 Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)  Folding Points: 14767 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 3 Days 20 h 9 m 42 sec
Reputation Power: 3163
Facebook MySpace
If you have it on more than one keyframe then make sure it has the instance name "solo" on them all. Does the button even exist when you are adding the event listener later on? If it's not on the stage at that point in time then it will be null.

Reply With Quote
  #5  
Old May 24th, 2011, 09:07 AM
ahillecke ahillecke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 27 ahillecke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 14 sec
Reputation Power: 0
The button is only in the first frame.

When the user clicks on the stage at the end of the game (pretty much any frame not the 1st), the playerhead is moved back to frame 1. The script trying to add the listener is also in frame 1, and the scripts before it , which are in frame 1, are being run without a hitch (traces still work up to the addEventListener).

I don't know if this is an indicator of anything, but the visual of the stage doesn't ever get to frame one, even though the frame 1 script is apparently executing. That's why I'm wondering if I misunderstand the timeline execution...does it read the script for the frame before it rerenders the stage, meaning that the button wouldn't be there 'til later?

Reply With Quote
  #6  
Old May 24th, 2011, 10:06 AM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 6,663 Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)  Folding Points: 14767 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 3 Days 20 h 9 m 42 sec
Reputation Power: 3163
Facebook MySpace
No, it's probably because of the error that it is stopping the loading process for the rest of the frames assets.

Are you using this.gotoAndStop(1); to return to the first keyframe? That's what you should be doing otherwise it might be playing past the first keyframe faster than you can see.

I'm like 99.9% sure having the code on a higher layer than the symbols makes no difference but you can always test that by dragging the code layer below the symbols.

Try wrapping the addListener line in a conditional, just for a quick test to see if the rest of the frame loads as expected graphically:
Code:
if(solo != null)
   {
      solo.addEventListener(MouseEvent.CLICK, this.goSolo);
   }

Reply With Quote
  #7  
Old May 24th, 2011, 10:44 AM
ahillecke ahillecke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 27 ahillecke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 14 sec
Reputation Power: 0
Hmm...now that's strange...

Putting in that little blurb showed that when it comes back to the first screen, the solo button is missing. It doesn't matter if that's the button clicked to go into the game or not...

I'll have to do some digging to figure out why it's disappearing...

Thanks for helping me find that.

Reply With Quote
  #8  
Old May 25th, 2011, 04:46 PM
ahillecke ahillecke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 27 ahillecke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 14 sec
Reputation Power: 0
Disappearing Button...

So my efforts to find out why the button is disappearing are so far fruitless.

I made solo keep it on frame 1, generate a pair of cards, and pretty much execute the game in frame 1...I've tried combinations of all matches, no match, match then no match so make the game "finish", and never got it to make the button disappear (all the game code was executed except going to the game frames). I even made it go to the game frames and return to the 1st frame without doing anything else, and the button still stayed.

Any ideas? It's the ONLY thing that's disappearing.

Reply With Quote
  #9  
Old May 26th, 2011, 03:45 AM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 6,663 Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)  Folding Points: 14767 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 3 Days 20 h 9 m 42 sec
Reputation Power: 3163
Facebook MySpace
Why not keep it there through the animation but set it to be not visible? So have a keyframe with solo on it at the start, then have normal frames till the end. On the second frame, on the ActionScript layer do:

solo.visible = false;

That will make it invisible and non mouse responsive. Then on the first keyframe make it visible:

solo.visible = true;

That way it should never be removed from the stage.

Reply With Quote
  #10  
Old May 26th, 2011, 09:21 AM
ahillecke ahillecke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 27 ahillecke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 7 m 14 sec
Reputation Power: 0
Not sure what exactly I did, but I rearranged the scripts a bit, and removed the call to go to the 2nd frame (instead, make the game initialize completely within the starting button rather than letting the frame do it), and it seems to work.

Now on to the next task ...

Reply With Quote
  #11  
Old May 26th, 2011, 09:27 AM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 6,663 Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)Tann San User rank is General 33rd Grade (Above 100000 Reputation Level)  Folding Points: 14767 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 3 Days 20 h 9 m 42 sec
Reputation Power: 3163
Facebook MySpace
Neat, glad you got it sorted.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsWeb DesignFlash Help > ActionScript 3 - Add EventListener on return to 1st frame

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap