Oliver Spryn
Oliver Spryn

Reputation: 17348

ActionScript 3 Alpha Tweening

I am building a custom preloader which is different than the "traditional" sliding bar that is common in RIAs. The preloader uses 100 white laser lights which are in a straight line, and collectively they indicate the progress bar. Let me describe how this works before I ask my question:

........................,,,,,,,,,:::::::::::::::::::::::::BBBBBBBB and so on...

The above string captures the spirit of the preloader indicator. In this illustration, the bigger and fatter the character, the brighter the laser light in my actual preloader:

  1. The farthest laser to the right indicates the currently loaded percentage. This is also the brightest laser light.
  2. All other trailing lasers get increasingly dimmer until they become completely black, as if they had burned a whole in the back of the screen.

Step "2" is where things get tricky. For some reason, the trialing lasers do not get darker, except for a few random lasers. Here is a snippet of the code controlling the brightness (or, as I used it, the alpha property) of the dot:

... more code ...

//Build the dots according the configuration and load status parameters
  private function buildDots(x:int, y:int):void {
  //Draw the dot, details not shown
    var dot:Shape = new Shape();

  //Begin the transitioning
    this.fadeOn(dot);
  }

//Fade a dot to full brightness
  private function fadeOn(dot:Shape):void {
    var fadeOn:Tween = new Tween(dot, "alpha", None.easeNone, 0, 1, this.fadeOnTime, true);

      fadeOn.addEventListener(TweenEvent.MOTION_FINISH, fadeOff);
  }

//Fade a dot to black
  private function fadeOff(e:TweenEvent):void {
    var fadeOff:Tween = new Tween(e.target.obj, "alpha", None.easeNone, 1, .2, this.fadeOffTime, true);
  }

... more code ...

Could someone please show me where I am going wrong? These details may help:

  1. This entire preloader is inside of a custom class.
  2. The laser lights are created completely by code, without access to the library.

Please let me know if I can provide any more details. I will reward a good answer/feedback with as many points as I can.

Thank you for all your time!

Upvotes: 0

Views: 1450

Answers (2)

Komsomol
Komsomol

Reputation: 742

The thing I see is a embedded function.

I would recode using the powerful TweenMax classes from Greensock. http://www.greensock.com/tweenmax/

Upvotes: 1

user677526
user677526

Reputation:

The only thing I'm seeing, offhand, is that you aren't removing an event listener from your fadeOn variable. That's the first thing I'd check out - I don't know much about tweening, but I do know that your event listener will cause the variable "fadeOn" to exist longer than it should, as it has a reference to it.

You might need to post more code, though. Perhaps someone with more tween experience can shed some more light.

Upvotes: 0

Related Questions