[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Changing the alpha of an instance in AS3

Posted on 2011-02-13
10
Medium Priority
?
371 Views
Last Modified: 2012-05-11
In Actionscript, I have created a For Loop to create six instances of a movie clip.  How can I change the alpha of each instance to be less than the instance before it?
var _boarder:mcBoarder;
var _boarderX:Number = 133;
var _boarderY:Number = 267;
var _boarderR:Number = 0;

for(var i:Number = 0; i < 6; i++)
{
	_boarder = new mcBoarder();
	addChild(_boarder);
	_boarder.x = _boarderX;
	_boarder.y = _boarderY;
	_boarder.rotation = _boarderR;
	_boarderX += 60;
	_boarderY -= 60;
	_boarderR -= 45;
}

Open in new window

0
Comment
Question by:MrJiggyHill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 1200 total points
ID: 34885058
Is it as simple as this?


var _boarder:mcBoarder;
var _prevBoarder:mcBoarder;
var _boarderX:Number = 133;
var _boarderY:Number = 267;
var _boarderR:Number = 0;

var _frameCount = 6;
var _firstAlpha = 100;
var _deltaAlpha = 10/ _frameCount ;

for(var i:Number = 0; i <  _frameCount ; i++)
{
      _boarder = new mcBoarder();
      addChild(_boarder);
      _boarder.x = _boarderX;
      _boarder.y = _boarderY;
      _boarder.rotation = _boarderR;
      if ( i == 0 ) _boarder.alpha = _firstAlpha;
      else _boarder.alpha = _prevBoarder.alpha - _deltaAlpha;
      _boarderX += 60;
      _boarderY -= 60;
      _boarderR -= 45;
      _prevBoarder = _boarder;
}
0
 

Author Comment

by:MrJiggyHill
ID: 34885072
Unfortunately not.  The alpha didn't change for each instance.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34885102
I think the "alpha" property may actually have an underscore, as in _boarder._alpha

Sorry 'bout that.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MrJiggyHill
ID: 34885132
No, I got compiler errors doing ._alpha
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34885161
Ok.  Go back to the original.  I had a typo (10 instead of 100).  Should read like this:

var _deltaAlpha = 100/ _frameCount ;

0
 
LVL 17

Assisted Solution

by:deepanjandas
deepanjandas earned 800 total points
ID: 34885199
First of all, as this is AS3, it cannot be _alpha, has to be .alpha.

Also the alpha values in AS3 ranges from 0-1.
So it will be in decimal.

var _firstAlpha = 1;
var _deltaAlpha = 1/ _frameCount ;


Warm Regards
Deepanjan Das
0
 

Author Comment

by:MrJiggyHill
ID: 34885204
still no change in the alpha
0
 

Author Comment

by:MrJiggyHill
ID: 34885217
Ah - that worked deepanjandas!  The alpha is now changing.  

Thank you guys very much!
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34885221
deepanjandas is right.  Corrected (and simplified) code.

var _boarder:mcBoarder;
var _boarderX:Number = 133;
var _boarderY:Number = 267;
var _boarderR:Number = 0;

var _frameCount = 6;
for(var i:Number = 0; i <  _frameCount ; i++)
{
      _boarder = new mcBoarder();
      addChild(_boarder);
      _boarder.x = _boarderX;
      _boarder.y = _boarderY;
      _boarder.rotation = _boarderR;
      _boarder.alpha = 1.0 * ( _frameCount - i ) / _frameCount;
      _boarderX += 60;
      _boarderY -= 60;
      _boarderR -= 45;
} 

Open in new window

0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34885227
Try this for alpha:
var frameCount:int = 6;
var baseAlpha:Number = 1/_frameCount;

for(var i:Number = _frameCount; i > 0; i--)
{
      _boarder = new mcBoarder();
      addChild(_boarder);

      _boarder.x = _boarderX;
      _boarder.y = _boarderY;
      _boarder.rotation = _boarderR;

      _boarder.alpha = baseAlpha * i;
      else _boarder.alpha = _prevBoarder.alpha - _deltaAlpha;

      _boarderX += 60;
      _boarderY -= 60;
      _boarderR -= 45;
      _prevBoarder = _boarder;
}

Open in new window


Warm Regards
Deepanjan Das
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question