在AS3中 - 我使用通用按钮处理程序来处理影片剪辑对象上的点击事件。在过去的4个小时里,我一直在尝试将图像添加到此影片剪辑(请参阅* * *)对象。AS3将图像添加到“扩展”影片剪辑
的代码(我剪切并粘贴了一点,但所有这一切编译没有任何错误)
btPlay = new mcButtonPlay(this,"ClickMe",GameImage); // GameImage is an BitmapData object
public class mcButtonPlay extends navigationButtonHandler {
public function mcButtonPlay(Parent:MovieClip,Text:String,GameImage:BitmapData) {
super(Text);
if (GameImage != null) {
var ImageBitMap:Bitmap = new Bitmap(GameImage);
this.addChild(ImageBitMap); // * * * This doesn’t show
Parent.addChild(ImageBitMap); // Works just to test the image
}
}
}
public class navigationButtonHandler extends MovieClip {
public function navigationButtonHandler(Text:String) {
ChangeButtonTargetText(Text);
Parent.addChild(this);
}
}
不确定你遇到的问题,但你应该看看AS3编码约定http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions围绕变量和类的大小写名。 – 2011-12-13 22:09:57
我不认为这会工作,因为你不能将参数传递给mcButtonPlay,而它扩展了一个扩展了movieclip的类......不会给你一个错误? – Eric 2011-12-13 22:26:05
总是要大写类名和大写变量名。这些都是强大的惯例。 作为一种风格,仅为事件处理程序(即函数)使用后缀“处理程序”。如果您想表示一个MovieClip,请添加后缀_mc。 – 2011-12-14 05:02:41