This content has been marked as final.
Show 17 replies
-
1. Re: Document Class access of button on a specific frame
kglad Jun 23, 2008 4:54 PM (in response to sneakyimp)you can't access it until the playhead enters that frame. -
2. Re: Document Class access of button on a specific frame
sneakyimp Jun 23, 2008 5:00 PM (in response to sneakyimp)If I'm not mistaken, the playhead should be on that frame because this line is immediately before my attempt to access it:
gotoAndStop('username');
That would take the playhead to the frame with the button (and this is in fact the behavior i see). However, I'm still getting the error.
Am I missing something here? -
3. Re: Document Class access of button on a specific frame
kglad Jun 23, 2008 7:22 PM (in response to sneakyimp)you must use the render event. -
4. Document Class access of button on a specific frame
sneakyimp Jun 23, 2008 9:49 PM (in response to kglad)That render event isn't described well anywhere. The adobe documentation barely mentions it and provides little useful info and no meaningful examples here:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html #event:render
I have the O'Reilly Actionscript 3.0 Cookbook (ISBN-10: 0-596-52695-4) which fails to mention it at all.
I googled around and found something semi-useful by Senocular at kirupa.com:
http://www.kirupa.com/forum/showthread.php?p=1914687
After some experimentation, I have the attached code working without errors but I have no idea if I've called the addEventListener method of the correct object or if I have written some very poor code or what. Any feedback would be greatly appreciated. -
5. Re: Document Class access of button on a specific frame
kglad Jun 23, 2008 10:08 PM (in response to sneakyimp)you should be in the right scope. (that is your document class, correct?)
just execute stage.invalidate() prior to your gotoAndStop(). (and you can use a trace(submitClick) to confirm your button exists in your onRenderUsername() function.) -
6. Re: Document Class access of button on a specific frame
sneakyimp Jun 23, 2008 10:20 PM (in response to sneakyimp)Yes that is my document class.
I'm executing stage.invalidate *after* my gotoAnStop statements which seems to work. Why should they be before them? -
7. Re: Document Class access of button on a specific frame
kglad Jun 23, 2008 11:00 PM (in response to sneakyimp)the invalidate() method needs to execute just prior to the playhead moving.
despite the invalidate() method following your goto method, it does execute before the playhead moves so it will work ok in your situation. -
8. Document Class access of button on a specific frame
sneakyimp Jun 25, 2008 12:40 PM (in response to kglad)I tried moving the stage.invalidate calls before the gotoAndStop calls and I get an error. Here's the trace window:
onConnect1 running! chatService has connected.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ChatExample/onRenderChat()
If I leave the stage.invalidate calls *before* the gotoAndStop calls, there are no errors. Perhaps there is something else wrong with my code? -
9. Re: Document Class access of button on a specific frame
kglad Jun 25, 2008 1:56 PM (in response to sneakyimp)use some trace() functions to pinpoint the code that's causing that error message. -
10. Re: Document Class access of button on a specific frame
sneakyimp Jun 25, 2008 3:03 PM (in response to kglad)I added six trace functions (see attached code) and the error went away. I remove the trace functions and the error comes back. Here's the trace window:
onConnect1 running! chatService has connected.
1
2
6 -
11. Re: Document Class access of button on a specific frame
kglad Jun 25, 2008 6:40 PM (in response to sneakyimp)that doesn't make sense unless there's some other timing issue. use trace(sendButton) in place of trace(1) and remove the other trace functions. -
12. Re: Document Class access of button on a specific frame
sneakyimp Jun 25, 2008 8:38 PM (in response to kglad)Replacing trace('1') with trace('sendButton') also causes the error to disappear and this is what the trace window says:
onConnect1 running! chatService has connected.
[object Button]
The altered function is attached below. Removing that trace function causes the error to return but not every time. I have noticed that it doesn't consistently appear. We appear to have race conditions of some kind? I don't think I understand how this could happen as Flash is not multithreaded, right? -
13. Re: Document Class access of button on a specific frame
kglad Jun 25, 2008 10:03 PM (in response to sneakyimp)flash is singlethreaded.
are you sure the error never occurs when there's a trace() function?
and how frequently does the error occur when there is no trace() function? -
14. Document Class access of button on a specific frame
sneakyimp Jun 25, 2008 11:24 PM (in response to kglad)OK...so I ran it twenty times with the trace(sendButton) function in there
WITH SEND BUTTON TRACE
Total times: 20
With Errors: 12
Without Errors: 8
Error Rate: 60%
I ran it 40 times with no trace function in there
WITH NO TRACE FUNCTION
Total: 40
With Errors: 18
Without Errors: 22
Error Rate: 45%
I'm totally baffled here as to why the behavior would not be consistent. I have attached the code I'm currently running (with the trace function in it) just for reference.
-
15. Re: Document Class access of button on a specific frame
sneakyimp Jun 25, 2008 11:25 PM (in response to kglad)OH...and one more thing. On only one occasion in those 60 runs, I got the same error on the onRenderUsername function. I'm not certain, but this bug seems to be related to the render event and the stage.invalidate() call. -
16. Re: Document Class access of button on a specific frame
sneakyimp Jun 30, 2008 10:19 PM (in response to sneakyimp)So is that all? My topic is ignored, left to slide into obscurity? A slow death of neglect and never an answer? Have I found a bug in Flash or is there something wrong with my code? -
17. Re: Document Class access of button on a specific frame
kglad Jul 1, 2008 10:44 AM (in response to sneakyimp)run some tests with your sendButton code commented out to check if that's the cause of your null reference error. if the error still occurs comment your removeEventListener() and retest.



