ajwei810192
03-17-2009, 09:17 PM
Hi, Guys:
I have an application here that I would like to allow users be able to select the color and change the color of the rectangle that was drawn programatically.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
width="800" height="250" initialize="init()"
>
<mx:Script>
<![CDATA[
import mx.core.*;
import flash.display.DisplayObject;
import flash.display.Sprite;
import mx.controls.Label;
import flash.geom.Point;
import flash.events.MouseEvent;
import mx.containers.Canvas;
import mx.controls.Image;
import mx.events.DragEvent;
import mx.managers.DragManager;
import mx.controls.Alert;
import flash.events.MouseEvent;
import mx.controls.HSlider;
public var myShapes:ShapesFactory;
public var rectangle:UIComponent;
private function init():void{
myShapes= new ShapesFactory();
}
private function drawRectangle():void{
rectangle=myShapes.Rectangle(72,42,138,72,0x00FFFF );
hbo1.addChild(rectangle);
}
private function update_color():void{
var myUint:uint = uint(cp.selectedColor);
if (myUint != 0xFFFFFF) {
rectangle= myShapes.Rectangle(72,42,138,72,myUint)
Alert.show("This is the new Color: " + myUint.toString());
}
else {
rectangle=myShapes.Rectangle(72,42,138,72,0x00FFFF );
}
}
]]>
</mx:Script>
<mx:HBox
id="hbo1"
borderSkin="CustomBorder"
backgroundColor="{cp.selectedColor}"
backgroundAlpha="0.8"
cornerRadius="14"
paddingLeft="20" paddingTop="20"
paddingRight="20" paddingBottom="20"
>
<mx:ColorPicker id="cp" showTextField="true" selectedColor="0xFFFFFF"/>
<mx:Text text="The HBox has a {'\r'}programmatic skin."
creationComplete="update_color();drawRectangle()"
/>
</mx:HBox>
</mx:Application>
Currently, the code has two possible problems that I am trying to solve but am not sure how.
1. How can I change the values from the hex mode to the actionscript mode that I could apply in the update_color() in my code?
2. Since I am trying to update the color, where should I put the change attribute in the code? Or, should I use something else?
I welcome any suggestions, and I mean anything.
I have an application here that I would like to allow users be able to select the color and change the color of the rectangle that was drawn programatically.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
width="800" height="250" initialize="init()"
>
<mx:Script>
<![CDATA[
import mx.core.*;
import flash.display.DisplayObject;
import flash.display.Sprite;
import mx.controls.Label;
import flash.geom.Point;
import flash.events.MouseEvent;
import mx.containers.Canvas;
import mx.controls.Image;
import mx.events.DragEvent;
import mx.managers.DragManager;
import mx.controls.Alert;
import flash.events.MouseEvent;
import mx.controls.HSlider;
public var myShapes:ShapesFactory;
public var rectangle:UIComponent;
private function init():void{
myShapes= new ShapesFactory();
}
private function drawRectangle():void{
rectangle=myShapes.Rectangle(72,42,138,72,0x00FFFF );
hbo1.addChild(rectangle);
}
private function update_color():void{
var myUint:uint = uint(cp.selectedColor);
if (myUint != 0xFFFFFF) {
rectangle= myShapes.Rectangle(72,42,138,72,myUint)
Alert.show("This is the new Color: " + myUint.toString());
}
else {
rectangle=myShapes.Rectangle(72,42,138,72,0x00FFFF );
}
}
]]>
</mx:Script>
<mx:HBox
id="hbo1"
borderSkin="CustomBorder"
backgroundColor="{cp.selectedColor}"
backgroundAlpha="0.8"
cornerRadius="14"
paddingLeft="20" paddingTop="20"
paddingRight="20" paddingBottom="20"
>
<mx:ColorPicker id="cp" showTextField="true" selectedColor="0xFFFFFF"/>
<mx:Text text="The HBox has a {'\r'}programmatic skin."
creationComplete="update_color();drawRectangle()"
/>
</mx:HBox>
</mx:Application>
Currently, the code has two possible problems that I am trying to solve but am not sure how.
1. How can I change the values from the hex mode to the actionscript mode that I could apply in the update_color() in my code?
2. Since I am trying to update the color, where should I put the change attribute in the code? Or, should I use something else?
I welcome any suggestions, and I mean anything.