Flash / Flex / ActionScript/Graphics/Controls — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 09:19, 26 мая 2010
Содержание
Creating an Item Renderer
package
{
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite
{
private var array:Array = ["one", "two", "three", "four", "five"];
public function Main()
{
super();
for(var i:int = 0; i < array.length; i++)
{
var spr:Sprite = new Sprite();
spr.graphics.beginFill(0x880088, 1);
spr.graphics.drawRect(0, 0, 100, 30);
spr.graphics.endFill();
var txt:TextField = new TextField();
txt.text = String(array[i]);
spr.addChild(txt);
addChild(spr);
spr.y = i * 32;
}
}
}
}
Draw the Play/Pause graphic
package{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.geom.Rectangle;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
public class Main extends Sprite {
public function Main( ) {
// Draw the Play/Pause graphic
graphics.beginFill(0xcccccc);
graphics.drawRoundRect(0, 0, 20, 16, 4, 4);
graphics.endFill( );
graphics.beginFill(0x333333);
graphics.moveTo(4, 4);
graphics.lineTo(8, 8);
graphics.lineTo(4, 12);
graphics.lineTo(4, 4);
graphics.drawRect(10, 4, 2, 8);
graphics.drawRect(14, 4, 2, 8);
graphics.endFill( );
}
}
}
Panel Control
package{
import flash.display.*;
import flash.events.*;
public class Main extends Sprite {
public var pan:Number = 0;
public function Main( )
{
addEventListener(MouseEvent.CLICK, onClick);
draw( );
}
public function onClick(event:MouseEvent):void
{
pan = event.localX / 50 - 1;
draw( );
dispatchEvent(new Event(Event.CHANGE));
}
private function draw( ):void {
graphics.beginFill(0xcccccc);
graphics.drawRect(0, 0, 102, 16);
graphics.endFill( );
graphics.beginFill(0x000000);
graphics.drawRect(50 + pan * 50, 0, 2, 16);
}
}
}
Volume Control
package{
import flash.display.*;
import flash.events.*;
public class Main extends Sprite {
public var volume:Number = 1.0;
public function Main( ){
addEventListener(MouseEvent.CLICK, onClick);
draw( );
}
public function onClick(event:MouseEvent):void
{
// When user clicks the bar, set the volume
volume = event.localX / 100;
draw( );
dispatchEvent(new Event(Event.CHANGE));
}
private function draw( ):void {
// Draw a bar and the current volume position
graphics.beginFill(0xcccccc);
graphics.drawRect(0, 0, 102, 16);
graphics.endFill( );
graphics.beginFill(0x000000);
graphics.drawRect(volume * 100, 0, 2, 16);
}
}
}