New York Design & Development Forums

Go Back   New York Design & Development Forums > Knowledge Bank > Tutorials
Connect with Facebook

Notices

Reply
 
LinkBack Thread Tools
Old 04-07-2006, 11:08 PM   #1 (permalink)
Senior Member
Fanatic
 
Michael's Avatar
 
Join Date: Mar 2006
Age: 26
Posts: 253
Michael is a glorious beacon of lightMichael is a glorious beacon of light
Send a message via AIM to Michael Send a message via MSN to Michael Send a message via Yahoo to Michael Send a message via Skype™ to Michael
Default Flash Alpha Innacuracies

Most people using Flash are unaware of the way it handles the alpha property. Many believe that it is a percentage from 0 - 100... which is understandable because this is how Flash allows you to handle it.

Well the truth is, it's not. It's actually converted to a number from 0 - 255. So when you set the _alpha property, Flash takes that value and converts it to it's appropriate percentage in the 0-255 base, the real problem is that the number is converted and rounded internally, which means you are completely unaware of not only the process, but it's results.

Alright so if you don't believe let's run a little test.

Open Flash and start a new file.
Then select Frame 1 and open the Actions Panel, paste the following code into the panel.

Code:
showAlpha();

function showAlpha()
{
   this._alpha = 0;
   for (var i = 0; i < 100; i++)
   {
      this._alpha++;
      trace(this._alpha);
   }
}
Quote:
Take note that we are not worried about the actual fading of the movieclip, we are only concerned with the values. This is the reason we are using a for loop, which would not be practical in a fading scenario.
If you run this code you will find that the last few results look like this..

Code:
75
75.78125
76.5625
77.34375
78.125
This really shows how unbelievably innacurate the alpha property is, in our example we end up more than 20% off of what we expected.

This innacuracy is also really bad because we are incrementing it, it wouldn't be so bad if we were manually setting each value, but the problem is that it's still innacurate.

Most percentage values have no corresponding exact value in the 0-255 range, but 5 of them do, they are:

0%, 25%, 50%, 75% and 100%

So how can we fix this innacuracy?

The method I use to make up for this innacuracy is simple, I wrote a class a while back for modifying alpha values for a particular movieclip, the drawback for this class is that their needs to be one instance for each MovieClip, the code for our custom AlphaModifier class is below...

Code:
class AlphaModifier 
{
   // the alpha property, we store this independent of the movieclips alpha property
   private var alpha:Number;
   // the movieclip that this AlphaModifier is targeting
   private var target:MovieClip

  /**
    * Constructor
    * @param The movieclip that we will be modifying with our AlphaModifier class.
    */
   public function AlphaModifier( target:MovieClip )
   {
      this.target = target;
      alpha = target._alpha;
   }

   /** 
     * Returns the alpha for the targeted movieclip.
     */
   public function get _alpha() : Number
   {
      return alpha;
   }

  /** 
    * Sets the alpha for the targeted movieclip.
    */
   public function set _alpha( alpha:Number ) : Void
   {
      target._alpha = alpha;
      this.alpha = alpha;
   }
}
[/php] 
Why this works is actually really simple.  Our biggest issue with the innacuracies in Flash are the fact that it rounds and converts internally.  Here we are storing our values independent of the _alpha of the target, so what we set the alpha to in the modifier, is what we get when we retrieve the value from the modifier.

This class is really simple to use, relying on object composition, here is a simple example to show the benefits from before.

[php]

var modifier = new AlphaModifier(_root);
modifier._alpha = 0;

for (var i = 0; i<100; i++) {
    modifier._alpha ++;
    trace(modifier._alpha);
}
If you have set up your class right, and you run this code, you will see that there is no innacuracies, you're alpha will be printed from 0-100. This is a small workaround, but it works.

Take Care.

_Michael
__________________
Actionscript Developer :P ...Dope...

http://www.createage.com
http://www.myspace.com/michaelxxoa <--- yeah I'm a nooob, so what

Last edited by danielmichel; 04-28-2006 at 05:45 PM.
Michael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 02-04-2009, 04:26 AM   #2 (permalink)
Junior Member
 
Join Date: Feb 2009
Posts: 3
honsikrey is on a distinguished road
Default Re: Flash Alpha Innacuracies

yeah, and an easier way is to write this:
var __alpha:Number=0;

for (var i=0;i<100;i++){
__alpha++
this._alpha=__alpha;
}
honsikrey is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 07-02-2011, 02:20 PM   #3 (permalink)
Senior Member
Fanatic
 
Join Date: Jun 2011
Posts: 403
desiuser is on a distinguished road
Default Re: Flash Alpha Innacuracies

They have a good job, although you can choose not to save media in the cloud or not. My question is from these decisions, to trust you do? (Microsoft, Google, IBM, Facebook, etc.). I've not yet on Apple's confidence. MS is focused on corporate, Google sell their data concentrated. Apple has always been consumer focused. burning avi to dvd mac Awesome! I have a little work to do to beef up my character! lol I may get whooped by higher level players! lol
desiuser is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Solutions to make flash video player consecutively play next flash video stephenz Multimedia Development 0 08-12-2009 05:58 AM


All times are GMT -4. The time now is 09:36 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45