📄 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 + -