A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: colorTransform update

  1. #1
    Member
    Join Date
    Jun 2009
    Posts
    35

    colorTransform update

    I cant seem to update the color of some simple graphics, which has me pretty stumped now.

    Code:
    	import flash.geom.ColorTransform;
    	import flash.display.*;
    	import flash.events.*;
    
    public class objects extends Sprite {
    		public var bigSquare:Sprite = new Sprite();
    		public var smallSquare:Sprite = new Sprite();
    		
    		
    		public function objects():void {
    			bigSquare.graphics.beginFill(0x2c6ccc); 
    			bigSquare.graphics.drawRect(20,50,200, 200);
    			
    			
    			smallSquare.graphics.beginFill(0x4cc5cc);
    			smallSquare.graphics.drawRect(300,170,100, 100);
    			
    			addChild(smallSquare);
    			addChild(bigSquare);
    			
    		}
    		
    		public function changeColor(object, color:uint):void {
    			
    			 var colorTransform:ColorTransform = bigSquare.transform.colorTransform;
                 colorTransform.color = color;
                 bigSquare.transform.colorTransform = colorTransform;
    			 trace(colorTransform.color);
    			 bigSquare.x = 500;
    			
     			
    		}
    	}
    when the changeColor function runs I get the trace output showing the selected color, however nothing happens to the graphics. I even added the line bigSquare.x = 500 to see if that had any effect but nothing. What am I missing?? thanks.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to create a new Colortransform instance, which you are not doing. here is the corrected script:
    PHP Code:
    public function changeColor (object:Objectcolor:uint):void
    {
        var 
    colorTransform:ColorTransform = new ColorTransform();
        
    colorTransform.color color;
        
    object.transform.colorTransform colorTransform;
        
    trace (colorTransform.color);

    - The right of the People to create Flash movies shall not be infringed. -

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