A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: ColorTransform query

  1. #1
    Senior Member
    Join Date
    May 2007

    ColorTransform query


    i am currently reading Learning Actionscript 3.0 A Beginners Guide and i'v stumbled on a code snippet tutorial that i hope you can explain to me, P.139. What i am trying to do is essentially create a particle system and the following code snippet i'm not sure about is the following

    var colorInfo:ColorTransform = ball.transform.colorTransform;
    The author Rich Shupe describes this piece of code as a way of storing the particle's default colorTransform information(allowing you to change the red,green,blue and alpha values) retrieved from the particles Transform object.

    However, what i don't understand is, if you want to store the particles default color transform information why not do it like this:

    var colorInfo:Transform = ball.transform;

    full code: particle.as
    	import flash.display.*;
    	import flash.geom.*
    	import flash.events.Event;
    	public class Particle extends Sprite {
    		private var _xpos:Number;
    		private var _ypos:Number;
    		private var _xvel:Number;
    		private var _yvel:Number;
    		private var _grav:Number;
    		public function Particle(xp:Number, yp:Number, xvel:Number, yvel:Number, grav:Number, col:uint) {
    			_xpos = xp;
    			_ypos = yp;
    			_xvel = xvel
    			_yvel = yvel
    			_grav = grav;
    			var ball:Sprite = new Ball();
    			x = _xpos;
    			y = _ypos;
    			alpha = .8;
    			scaleX = scaleY = Math.random() * 1.9 + .1;
    			var colorInfo:ColorTransform = ball.transform.colorTransform;
    			colorInfo.color = col;
    			ball.transform.colorTransform = colorInfo;
    			addEventListener(Event.ENTER_FRAME, onRun, false, 0, true);
    		private function onRun(evt:Event):void {
    			_yvel += _grav;
    			_xpos += _xvel;
    			_ypos += _yvel;
    			x = _xpos;
    			y = _ypos;
    			if (_xpos < 0 || _ypos < 0 || _xpos > stage.stageWidth || _ypos > stage.stageHeight) {
    			   removeEventListener(Event.ENTER_FRAME, onRun);

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Oregon, USA
    You have to re-apply the colorTransform for it to take effect on the object - just calling in and changing the .color property won't force it to be redrawn correctly. It's a weird little workaround but it's necessary to save the reference to the object first and then re-assign it after you make the change.
    Please use [php] or [code] tags, and mark your threads resolved 8)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center