请问flash as3中的addchild()是干什么用的,看帮助文件没看明白
1个回答
展开全部
看这个,我实例化了两个文本框,如里你不用addChild将它们放到舞台上,它们是不会显示出来的。
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextFieldType;
public class textfield extends Sprite{
private var inputtext:TextField = new TextField();
private var outputtext:TextField = new TextField();
public function textfield() {
inputtext.border = true;
inputtext.background = true;
inputtext.backgroundColor = 0x0000ff;
inputtext.type = TextFieldType.INPUT;
inputtext.x = 100;
inputtext.y = 30;
inputtext.width = 100;
inputtext.height = 25;
outputtext.border = true;
outputtext.background = true;
outputtext.backgroundColor = 0xff00e5;
outputtext.x = 100;
outputtext.y = 100;
outputtext.width = 100;
outputtext.height = 25;
inputtext.addEventListener(TextEvent.TEXT_INPUT , textinputHandler);
addChild(inputtext);
addChild(outputtext);
}
private function textinputHandler(e:TextEvent):void {
var pressdkey:String = e.text;
outputtext.text = pressdkey;
}
}
}
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextFieldType;
public class textfield extends Sprite{
private var inputtext:TextField = new TextField();
private var outputtext:TextField = new TextField();
public function textfield() {
inputtext.border = true;
inputtext.background = true;
inputtext.backgroundColor = 0x0000ff;
inputtext.type = TextFieldType.INPUT;
inputtext.x = 100;
inputtext.y = 30;
inputtext.width = 100;
inputtext.height = 25;
outputtext.border = true;
outputtext.background = true;
outputtext.backgroundColor = 0xff00e5;
outputtext.x = 100;
outputtext.y = 100;
outputtext.width = 100;
outputtext.height = 25;
inputtext.addEventListener(TextEvent.TEXT_INPUT , textinputHandler);
addChild(inputtext);
addChild(outputtext);
}
private function textinputHandler(e:TextEvent):void {
var pressdkey:String = e.text;
outputtext.text = pressdkey;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询