?? as源碼.as
字號:
package {
import flash.display.*;
import flash.events.*;
import flash.text.TextField;
//發送事件
/*
public class Example extends EventDispatcher
{
...
}
*/
//import mx.events.ModuleEvent;
//[SWF(width = "500", height = "500", backgroundColor = "#ffcfdf", frameRate = "31")]
public class eofFlex extends Sprite
{
private var _sprite:Sprite; //私有變量。按照習慣約定,private和protected都在前面加上下劃線“_”
private var _square:Sprite;
private var _circle:Sprite
private var _label:TextField;
public function eofFlex()
{
//調用其他成員函數
//testDraw();
//如何調試?
//var userName:String = "Bill Smith";
//trace("My name is " + userName + ".");
//處理事件
//graphics.lineStyle(1, 0, 1);
//addEventListener(Event.ENTER_FRAME, onEnterFrame);
//響應鼠標和鍵盤事件
/*
_sprite = new Sprite();
addChild(_sprite);
_sprite.graphics.beginFill(0xffffff);
_sprite.graphics.drawRect(100, 100, 200, 200);
_sprite.graphics.drawCircle(100, 100, 50);
_sprite.graphics.endFill();
_sprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
_sprite.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.focus = this;
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
*/
/*
var quantity:int = 5;
if (quantity is int) //判斷是否為int類型
{
trace("Yippee. It's an integer.");
}
*/
//長時間執行一個任務
_square = new Sprite();
_square.graphics.beginFill(0xff0000);
_square.graphics.drawRect(0, 0, 100, 100);
_square.graphics.endFill();
//addChild(_square);
_square.x = 100;
_square.y = 50;
_circle = new Sprite();
_circle.graphics.beginFill(0x0000ff);
_circle.graphics.drawCircle(50, 50, 50);
_circle.graphics.endFill();
//addChild(_circle);
_circle.x = 100;
_circle.y = 200;
//創建兩個定時器,啟動
//var squareTimer:Timer = new Timer(50, 0);
//squareTimer.addEventListener(TimerEvent.TIMER, onSquareTimer);
//squareTimer.start();
//var circleTimer:Timer = new Timer(100, 0);
//circleTimer.addEventListener(TimerEvent.TIMER, onCircleTimer);
//circleTimer.start();
//在可視化對象列表中添加項目
var hello:TextField = new TextField();
hello.text = "Hello, ayou!";
addChild(hello);
var hi:TextField = new TextField();
hi.text = "Hi, ayou!";
hi.x = 50;
hi.y = 60;
var container:Sprite = new Sprite();
container.addChild(hi);
DisplayObjectContainer(root).addChild(container);
//可視化對象的深度
var red:Shape = createCircle(0xff0000, 10);
red.x = 10;
red.y = 20;
var green:Shape = createCircle(0x00ff00, 10);
green.x = 15;
green.y = 25;
var blue:Shape = createCircle(0x0000ff, 10);
blue.x = 20;
blue.y = 20;
addChild(red);
addChildAt(green, 1);
addChild(blue);
//在可視化對象列表中刪除項目
_label = new TextField();
_label.text = "Some Text!!!!!!!!!!!!!!!!!!!!!!!1";
addChild(_label);
//stage.addEventListener(MouseEvent.CLICK, removeLabel);
//創建自定義可視化類
//圖形類:繼承Shape
//按鈕:繼承SimpleButton
//不需要時間線的容納其他對象的容器:繼承Sprite
//需要時間線的容納其他對象的容器:繼承MovieClip
var testCircle:Circle = new Circle(0xff0000, 100);
testCircle.x = 200;
testCircle.y = 200;
//addChild(testCircle);
//創建簡單的按鈕
var button:SimpleButton = new SimpleButton();
button.x = 300;
button.y = 300;
button.upState = createBtCircle(0x00ff00, 15);
button.overState = createBtCircle(0xffffff, 16);
button.downState = createBtCircle(0xcccccc, 15);
button.hitTestState = button.upState;
//button.hitTestState = createBtCircle(0x000000, 20);
button.addEventListener(MouseEvent.CLICK, handleClick);
addChild(button);
}
private function testDraw():void
{
graphics.lineStyle(1, 0, 1);
for (var i:int = 0; i < 100; i++)
{
graphics.lineTo(Math.random() * 400, Math.random() * 400);
}
}
private function onEnterFrame(event:Event):void
{
graphics.lineTo(Math.random() * 400, Math.random() * 400);
//_sprite.rotation += 5;
}
private function onMouseDown(event:MouseEvent):void
{
_sprite.graphics.lineStyle(1, 0, 1);
_sprite.graphics.moveTo(mouseX, mouseY);
_sprite.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseUp(event:MouseEvent):void
{
_sprite.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onKeyDown(event:KeyboardEvent):void
{
trace("Key down: " + event.charCode);
}
private function onMouseMove(event:MouseEvent):void
{
_sprite.graphics.lineTo(mouseX, mouseY);
}
private function onSquareTimer(event:TimerEvent):void
{
_square.x++;
}
private function onCircleTimer(event:TimerEvent):void
{
_circle.x++;
}
private function createCircle(color:uint, radius:Number):Shape
{
var shape:Shape = new Shape();
shape.graphics.beginFill(color);
shape.graphics.drawCircle(0, 0, radius);
shape.graphics.endFill();
return shape;
}
private function removeLabel(event:MouseEvent):void
{
//removeChild(_label);
if (numChildren > 0)
{
removeChildAt(0);
}
}
private function createBtCircle(color:uint, radius:Number):Shape
{
var circle:Shape = new Shape();
circle.graphics.lineStyle(1, 0x000000);
circle.graphics.beginFill(color);
circle.graphics.drawCircle(0, 0, radius);
circle.graphics.endFill();
return circle;
}
private function handleClick(event:MouseEvent):void
{
trace("Mouse clicked on the button.");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -