You are here: Home > > Cara Membatasi Warna di ColorPicker

Cara Membatasi Warna di ColorPicker

Dalam tutorial ini kamu akan belajar caranya membatasi jumlah warna di colourpicker.
Jadi jika kamu hanya menginginkan beberapa warna, kamu dapat membatasinya sendiri.
Untuk itu kamu memerlukan color properties dari colorpicker component.
saya memberikan contoh beberapa warna yaitu merah, kuning, biru dan hijau.



1.
buat file baru
pilih Window > components dan drag colorpicker component ke library.

2.
pada timeline masukkan new layer dinamakan Actions dan masukkan kode berikut dalam actions panel. Untuk membatasi warna, kamu harus mengubah angka hexadesimal pada script yang dicetak miring dibawah ini.

//Import the packages needed.
import fl.events.ColorPickerEvent;
import fl.controls.ColorPicker;
import flash.geom.ColorTransform;

/*Creates a new instance of the a sprite class which fills the whole stage area
in black colour, and add the display object at the bottom position (index 0).*/
var bgColour:Sprite = new Sprite();
bgColour.graphics.beginFill(0x000000);
bgColour.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
addChildAt(bgColour,0);

//Creates a new instances of the colour picker class.
var mycolorPicker:ColorPicker = new ColorPicker();

//Limit the colours to red, yellow, green, and blue.
mycolorPicker.colors = [ 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00];

/*Moves the colour picker to (20,20) and set the size to (50,50) and add the
component on the stage.*/
mycolorPicker.move(20, 20);
mycolorPicker.setSize(50, 50);
addChild(mycolorPicker);

//Add the change event to the colour picker.
mycolorPicker.addEventListener(ColorPickerEvent.CHANGE, changeBg);

function changeBg (event:ColorPickerEvent):void {
//Creates a new instance of the ColorTrasform class.
var myColorTransform:ColorTransform = bgColour.transform.colorTransform;

//An instance of selected colour from the colour picker.
var theColor:Number=mycolorPicker.selectedColor;

//Sets the new colour from the colour picker.
myColorTransform.color=theColor;

//Apply the colour changes to the movie clip.
bgColour.transform.colorTransform=myColorTransform;
}


3.
sekarang tes movie clip dengan cara ctrl + enter. Sekarang coba klik color picker dan kamu akan mendapatkan empat warna tersebut di dalam palette.
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

0 Responses to “Cara Membatasi Warna di ColorPicker”:

Leave a comment