View Full Version : Runtime generated sprites sometimes stick to zero x and y coordinate...ideas?
marlonpando
November 19th, 2009, 11:27 AM
I have bug in an actionscript 3.0 mp3 player i've written where all of the graphics (ui) are generated by actionscript at run-time but occasionally they all get stuck on the zero x and y coordinate making the program difficult to interface with. I set the coordinates of the sprites with some math: stage.stageWidth/2 and stage.stageHeight/2 for instance.
I don't know in which particular browsers this tends to be a problem but it has happened in Firefox and IE, though not consistently, which is really confusing. Has anything similar happened to anyone and might they please share their insight? Is it my fault or someone else's (i.e. - adobe, ms, mozilla, etc.)?
Many thanks to any who care to share their experience.
senocular
November 19th, 2009, 11:40 AM
You should make sure those values are non-0 before setting. Some conditions can cause them to be 0 in some browsers when the swf starts, and I think this is sometimes a result of the SWF loading offscreen (such as further down the HTML page but not yet visible).
marlonpando
November 19th, 2009, 11:47 AM
Thank you senocular. As I'm at work I'm not able to try your suggestion at the moment but I really appreciate the great advice. I will definitely give it a go later. Thanks again.
0L4F
November 19th, 2009, 04:24 PM
This is exactly the reason why a lot of my document class constructors look like this (and I love the ternary operator ;) ):
(stage) ? init() : addEventListener(Event.ADDED_TO_STAGE, init));
...and then, in my init() function, I remove the listener and start initializing and adding children to the stage. You can't do that if you don't have access to the stage property.
marlonpando
November 19th, 2009, 04:51 PM
Thank you 0L4F for that chunky bit of advice. I had no idea what could be the problem and now I'm in a much better place thanks to you guys. I like your solution 0L4F - it should help me quite a bit.
0L4F
November 19th, 2009, 05:24 PM
Glad to be of help. This piece of code saved me from so much headaches that I thought I could write it down form the top of my head. But I made a typo there, one right parenthesis too much, whoops. It should be:
(stage) ? init() : addEventListener(Event.ADDED_TO_STAGE, init);
marlonpando
November 19th, 2009, 11:32 PM
For the short term, to store the height and width of the stage I assign a variable number for each rather than by accessing the stage properties. I think this will work for now until I can get a handle on when to access the stage.
You have helped me to see the error of my ways and now I must rewrite a bit of code. Thanks for sharing the benefit of your experience. This is a really great forum.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.