I have a preloader_mc that will scaleX until it hits stageWidth. Everything works when I test and when I trace out “totalLoaded”.
I noticed that if I simulate download at DSL speeds. The preloader_mc scaleX will reach the stageWidth way before the trace of totalLoaded has hit the stageWidth? I am not sure if something is messed up with my code or what the problem is.
[AS]
private function _onLoadProgress($evt:ProgressEvent):void
{
var totalLoaded:Number = Math.floor($evt.bytesLoaded / $evt.bytesTotal * stage.stageWidth);
scaleX = totalLoaded;
trace(totalLoaded);
}[/AS]
The value of scaleX in AS3 is different to AS2. In AS3 0.0 equals 0% and 1.0 equals 100%
It would be better to set the width instead of the scaleX value:
[as]width = stage.stageWidth * ( 1.0 / totalLoaded );[/as]
Off topic, but you should try to get out of the habit of prefixing your variables with $ because that is just a PHP thing. Prefixing methods with an underscore is also a bit odd.
- 20 October 2007 01:37 AM
-
or he can just divide by 100.
[AS]
scaleX = totalLoaded / 100;
[/AS]
as far as prefixing, that’s just user preference. i use underscores and $ quite often ($ for private static/constants, underscore for private vars). some prefer to have coding standards to make development in a team environment easier. to me, as long as you’re not obfuscating your variable names too much, it doesn’t really matter if you prefix variables with special legal characters.
- 20 October 2007 11:42 AM
-
In Isocase’s code dividing by 100 wouldn’t have worked because the value of totalLoaded is the stage width, or will be when the load progress is complete. It isn’t a percentage.
As for prefixing variables with $ then yes, that is personal preference, but it is going to be a nightmare for anyone else who may need to debug/modify the code. If you don’t work with other developers though then I guess it doesn’t make much difference if you use $ or not.
- 20 October 2007 01:31 PM
-
Thanks Nutrox and Sentinels. I forgot how in AS3 0 equals 0% and 1 equals 100%. Kinda like how alpha values are between 0 - 1.
When I first started coding the person teaching me would always use $ for his parameters (I think he learned that from BigSpaceship) just so its easy to find. AS well as using underscore for private vars and methods. But if I am working with other Devs I will take it into consideration.
- 20 October 2007 06:51 PM
-
Maybe I am just tired or feeling stupid after my flag football game but what am I doing wrong
[AS]
private function _onLoadProgress($evt:ProgressEvent):void
{
var totalLoaded:Number = Math.floor($evt.bytesLoaded / $evt.bytesTotal * stage.stageWidth);
width = stage.stageWidth * ( 1.0 / totalLoaded );
trace(width);
}
[/AS]
This is what gets traced out:
[AS]
327680
327680
327680
327680
327680
327680
327680
327680
327680
327680
327680
327680
900
327680
900
[/AS]
My stage is set at 900.
- 20 October 2007 07:55 PM
-
I was finally able to get his working. I tried using what Nutrox posted but as you can see above I was getting some weird stuff traced out. I did change from using scaleX to width and below is what works
[AS]
private function _onLoadProgress($evt:ProgressEvent):void
{
var totalLoaded:Number = Math.floor($evt.bytesLoaded / $evt.bytesTotal * stage.stageWidth);
width = totalLoaded;
trace(“totalLoaded: ” + totalLoaded);
}
[/AS]
- 21 October 2007 06:31 PM
-
- Log in or join for free to make a comment.


