请教大师SimpleButton做了一个例子老报错
时间:2010-12-09
来源:互联网
如下代码老报:文件不能有一个以上外部可见的定义:TestBtn,Mybn1
复制内容到剪贴板
{
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
public class TestBtn extends Sprite
{
private var btn1:MyBtn1;
private var btn2:MyBtn2;
private var input:TextField;
public function TestBtn()
{
initMc();
}
private function initMc()
{
//btn1
btn1 = new MyBtn1("myBtn1",150,20,"我的文字有不同的颜色哦");
btn1.x = 10;
btn1.y = 10;
addChild(btn1);
//btn2
btn2 = new MyBtn2("myBtn2",150,20,"把我的按钮文字换成:");
btn2.x = 180;
btn2.y = 10;
addChild(btn2);
btn2.addEventListener(MouseEvent.CLICK,onClickBtn2);
//input
input = new TextField();
input.border = true;
input.borderColor = 0xff66ff;
input.type = TextFieldType.INPUT;
input.x = 340;
input.y = 10;
input.width = 150;
input.height = 20;
input.text = "在此输入要换成的文字";
addChild(input);
}
public function onClickBtn2(event:MouseEvent):void
{
var txt:TextField = btn2.getChildByName("btnTxt");
txt.text = input.text;
}
}
internal class MyBtn1 extends SimpleButton{
private var upColor:uint = 0x000066;
private var overColor:uint = 0xffccff;
private var downColor:uint = 0x660000;
public function MyBtn1(name:String,w:uint,h:uint,txt:String)
{
this.name = name;
downState = new BtnStatusShape1(downColor,w,h,txt);
overState = new BtnStatusShape1(overColor,w,h,txt);
upState = new BtnStatusShape1(upColor,w,h,txt);
hitTestState = upState;
}
}
internal class BtnStatusShape1 extends Sprite{
public function BtnStatusShape1(bgColor:uint,w:uint,h:uint,txt:String)
{
graphics.lineStyle(1,0x000000,0.8);
graphics.beginFill(bgColor,0.8);
graphics.drawRoundRect(0,0,w,h,8);
graphics.endFill();
addChild(new BtnTxt(w,h,txt,0xffffff - bgColor));
}
}
internal class MyBtn2 extends Sprite{
private var upColor:uint = 0x660000;
private var overColor:uint = 0x333300;
private var downColor:uint = 0x000066;
private var btn:SimpleButton;
public function MyBtn2(name:String,w:uint,h:uint,txt:String)
{
this.name = name;
btn = new SimpleButton();
btn.name = "btn";
btn.downState = new BtnStatusShape2(downColor,w,h);
btn.overState = new BtnStatusShape2(overColor,w,h);
btn.upState = new BtnStatusShape2(upColor,w,h);
btn.hitTestState = btn.upState;
addChild(btn);
addChild(new BtnTxt(w,h,txt,0xffffff));
}
public override function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0,useWeakReference:Boolean = false):void{
btn.addEventListener(type,listener);
}
}
internal class BtnStatusShape2 extends Shape{
public function BtnStatusShape2(bgColor:uint,w:uint,h:uint)
{
graphics.lineStyle(1,0x000000,0.8);
graphics.beginFill(bgColor,0.8);
graphics.drawRoundRect(0,0,w,h,8);
graphics.endFill();
}
}
internal class BtnTxt extends TextField{
public function BtnTxt(w:uint,h:uint,txt:String,bgColor:uint)
{
name = "btnTxt";
width = w;
height = h;
textColor = bgColor;
text = txt;
autoSize = TextFieldAutoSize.CENTER;
selectable = false;
mouseEnabled = false;
mouseWheelEnabled = false;
}
}
}
代码:
package{
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
public class TestBtn extends Sprite
{
private var btn1:MyBtn1;
private var btn2:MyBtn2;
private var input:TextField;
public function TestBtn()
{
initMc();
}
private function initMc()
{
//btn1
btn1 = new MyBtn1("myBtn1",150,20,"我的文字有不同的颜色哦");
btn1.x = 10;
btn1.y = 10;
addChild(btn1);
//btn2
btn2 = new MyBtn2("myBtn2",150,20,"把我的按钮文字换成:");
btn2.x = 180;
btn2.y = 10;
addChild(btn2);
btn2.addEventListener(MouseEvent.CLICK,onClickBtn2);
//input
input = new TextField();
input.border = true;
input.borderColor = 0xff66ff;
input.type = TextFieldType.INPUT;
input.x = 340;
input.y = 10;
input.width = 150;
input.height = 20;
input.text = "在此输入要换成的文字";
addChild(input);
}
public function onClickBtn2(event:MouseEvent):void
{
var txt:TextField = btn2.getChildByName("btnTxt");
txt.text = input.text;
}
}
internal class MyBtn1 extends SimpleButton{
private var upColor:uint = 0x000066;
private var overColor:uint = 0xffccff;
private var downColor:uint = 0x660000;
public function MyBtn1(name:String,w:uint,h:uint,txt:String)
{
this.name = name;
downState = new BtnStatusShape1(downColor,w,h,txt);
overState = new BtnStatusShape1(overColor,w,h,txt);
upState = new BtnStatusShape1(upColor,w,h,txt);
hitTestState = upState;
}
}
internal class BtnStatusShape1 extends Sprite{
public function BtnStatusShape1(bgColor:uint,w:uint,h:uint,txt:String)
{
graphics.lineStyle(1,0x000000,0.8);
graphics.beginFill(bgColor,0.8);
graphics.drawRoundRect(0,0,w,h,8);
graphics.endFill();
addChild(new BtnTxt(w,h,txt,0xffffff - bgColor));
}
}
internal class MyBtn2 extends Sprite{
private var upColor:uint = 0x660000;
private var overColor:uint = 0x333300;
private var downColor:uint = 0x000066;
private var btn:SimpleButton;
public function MyBtn2(name:String,w:uint,h:uint,txt:String)
{
this.name = name;
btn = new SimpleButton();
btn.name = "btn";
btn.downState = new BtnStatusShape2(downColor,w,h);
btn.overState = new BtnStatusShape2(overColor,w,h);
btn.upState = new BtnStatusShape2(upColor,w,h);
btn.hitTestState = btn.upState;
addChild(btn);
addChild(new BtnTxt(w,h,txt,0xffffff));
}
public override function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0,useWeakReference:Boolean = false):void{
btn.addEventListener(type,listener);
}
}
internal class BtnStatusShape2 extends Shape{
public function BtnStatusShape2(bgColor:uint,w:uint,h:uint)
{
graphics.lineStyle(1,0x000000,0.8);
graphics.beginFill(bgColor,0.8);
graphics.drawRoundRect(0,0,w,h,8);
graphics.endFill();
}
}
internal class BtnTxt extends TextField{
public function BtnTxt(w:uint,h:uint,txt:String,bgColor:uint)
{
name = "btnTxt";
width = w;
height = h;
textColor = bgColor;
text = txt;
autoSize = TextFieldAutoSize.CENTER;
selectable = false;
mouseEnabled = false;
mouseWheelEnabled = false;
}
}
}
作者: gaowenzhen 发布时间: 2010-12-09
package內不能寫多個類定義。你寫成包外類吧。
作者: enc0717 发布时间: 2010-12-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28