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
Solved

Changing the alpha of an instance in AS3

Posted on 2011-02-13
10
366 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
  • 4
  • 4
  • 2
10 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 300 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 200 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSLT 5 48
Google adds suggestions 3 69
Problem to file 3 83
Cordova Camera plugin fails 2 140
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

837 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