as 3 绘图板示例与组件使用实例
as 3 绘图板示例与组件使用实例
package
{
import flash.display.sprite;
import flash.events.mouseevent;
public class classgraphics extends sprite
{
private var mysprite:sprite;
// 构造函数
public function classgraphics()
{
this.mysprite = new sprite();
addchild(this.mysprite);
this.mysprite.graphics.beginfill(0x336699);
this.mysprite.graphics.drawrect(0, 0, 550, 400);
this.mysprite.graphics.endfill();
this.mysprite.addeventlistener(mouseevent.mouse_down, spritemousedown);
this.mysprite.addeventlistener(mouseevent.mouse_up, spritemouseup);
}
// 鼠标按下事件
private function spritemousedown(event:mouseevent):void
{
this.mysprite.graphics.linestyle(1, 0, 1);
this.mysprite.graphics.moveto(mou易做图, mousey);
this.mysprite.addeventlistener(mouseevent.mouse_move, spritemousemove);
}
// 鼠标离开事件
private function spritemouseup(event:mouseevent):void
{
this.mysprite.removeeventlistener(mouseevent.mouse_move, spritemousemove);
}
// 移动事件
private function spritemousemove(event:mouseevent):void
{
this.mysprite.graphics.lineto(mou易做图, mousey);
}
}
}
组件使用
package com
{
import flash.display.sprite;
import flash.events.mouseevent;
import flash.display.stagescalemode;
import flash.display.stagealign;
import fl.controls.label;
import fl.controls.textinput;
import fl.controls.textarea;
import fl.controls.button;
public class classmain extends sprite
{
private var username:textinput;
private var usernamelabel:label;
private var message:textarea;
private var messagelabel:label;
private var button:button;
// 构造函数
public function classmain()
{
stage.scalemode = "noscale";
stage.align = stagealign.top_left;
this.initmc();
}
// 一点准备工作
private function initmc():void
{
this.username = new textinput();
addinput(this.username, "username", 50, 10, 200, 18);
this.usernamelabel = new label();
addlabel(this.usernamelabel, "呢称:", 10, 10, 40, 18);
this.message = new textarea();
addtextarea(this.message, "message", 50, 40, 400, 100);
this.messagelabel = new label();
addlabel(this.messagelabel, "留言:", 10, 40, 40, 18);
this.button = new button();
addbutton(this.button, "提交", 350, 150);
}
// 创建label
private function addlabel(label:label, text:string, x:uint, y:uint, width:uint, height:uint):void
{
label.text = text;
label.move(x, y);
label.setsize(width, height);
addchild(label);
}
// 创建文本框
private function addinput(input:textinput, name:string, x:uint, y:uint, width:uint, height:uint):void
{
input.name = name;
input.move(x, y);
input.setsize(width, height);
addchild(input);
}
// 创建文本域
private function addtextarea(textarea:textarea, name:string, x:uint, y:uint, width:uint, height:uint):void
{
textarea.name = name;
textarea.move(x, y);
textarea.setsize(width, height);
textarea.condensewhite = true;
addchild(textarea);
}
// 创建按钮
private function addbutton(button:button, value:string, x:uint, y:uint):void
{
button.label= value;
button.move(x, y);
addchild(button);
}
}
}
补充:flash教程,As3.0