The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • ActionScript
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 ActionScript

  • Isocase Author 
    • 1922 
    • 0 
    • 6 
    [AS3] Preloader observation
    Isocase

    Last reply Oct 21 2007, 06:31 PM

    by Isocase

    Posted: Oct 20 2007, 01:00 AM

    by Isocase

     

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]

  6 REPLIES
 
Nutrox
1  
Nutrox

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.

smilie

  • 20 October 2007 01:37 AM
  •  
sentinels
2  
sentinels

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. smilie

  • 20 October 2007 11:42 AM
  •  
Nutrox
3  
Nutrox

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.

smilie

  • 20 October 2007 01:31 PM
  •  
Isocase Author 
4  
Isocase

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
  •  
Isocase Author 
5  
Isocase

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
  •  
Isocase Author 
6  
Isocase

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.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 780  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,729  Assets
  • Profiles 284,156  Members
  • Topics 93,805  Topics
  • Blog 4  Blog
  • Facebook 1,679  Facebook
  • Twitter 1,160  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Thu, February 23, 2012 - 18:25:59