如何制作颜色选择器,选择三种不同的颜色?

时间:2012-01-07 09:43:43

标签: actionscript-3 flash-cs5

我希望能够从颜色选择器中选择三种不同的颜色。我想选择红色,绿色和蓝色。如何更改下面的代码才能执行此操作?我应该把自己的颜色选择器放在自己的班级吗?

    public class SuperDraw extends Sprite
{
    private var loadImage:LoadImage;
    private var saveImage:SaveImage;
    private var graphic:GameGraphic;
    private var bmp:Bitmap;
    private var pencilDraw:Shape;
    private var p:Point;
    //private var backGroundGame:backGround;

    private var backGroundDraw:drawTabel;

    private static var penSprite:Sprite;
    private static var mouseDownFlag:Boolean;

    protected var penSprite:Sprite = new Sprite();    

    // Bitmap där ritandet sparas.
    protected var canvasBitmap:Bitmap;    

    public function SuperDraw()
    {   
        graphic = new GameGraphic();
        loadImage = new LoadImage();
        saveImage = new SaveImage();
        backGroundDraw = new drawTabel();

        //-------------------------------------------

        // Skapa en backgrund där ritandet ska visas.  
        this.canvasBitmap = new Bitmap( new BitmapData( this.stage.stageWidth, this.stage.stageHeight ), "auto", true );

        // Adda alla klasser och ha graphic klassen ovanför penSprite.
        this.addChild(graphic);
        this.addChild(backGroundDraw);
        this.addChild(penSprite);
        this.addChild(saveImage);
        this.addChild(loadImage);

        this.penSprite.graphics.lineStyle(3, 0x000000 );

        this.stage.addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDown);
    }

    private function mouseDown(e:MouseEvent):void 
    {
        this.stage.addEventListener(MouseEvent.MOUSE_MOVE, this.mouseMove);
        this.stage.addEventListener(MouseEvent.MOUSE_UP,   this.mouseUp);
    }

    private function mouseMove(e:MouseEvent):void 
    {
        penSprite.graphics.lineTo( e.localX, e.localY );
    }

    // Skapar funktionen mouseUp.
    private function mouseUp(e:MouseEvent):void
    {
        // Ritar och sparar till bitmapData.
        canvasBitmap.bitmapData.draw( penSprite, null, null, null, null, true );

        // Ta bort alla listeners. 
        this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
        this.stage.removeEventListener(MouseEvent.MOUSE_UP,   mouseUp);
    }           
}

1 个答案:

答案 0 :(得分:0)

也许你想要这个

import fl.controls.ColorPicker;

var cp:ColorPicker = new ColorPicker();
cp.colors = [ 0xff0000,0x00ff00,0x0000ff];
addChild(cp);

有关详情,请访问http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/ColorPicker.html