【发布时间】:2011-12-13 21:41:14
【问题描述】:
在 AS3 中 - 我使用通用按钮处理程序来处理影片剪辑对象上的单击事件。在过去的 4 小时里,我一直在尝试将图像添加到此影片剪辑(请参阅 * * *)对象。
代码(我剪切并粘贴了一点,但这一切都编译没有任何错误)
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);
}
}
【问题讨论】:
-
不确定您遇到的问题,但您可能应该在opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions 中查看关于变量和类名大写的 AS3 编码约定。
-
我不认为这会起作用,因为你不能将参数传递给 mcButtonPlay 而它扩展了一个扩展movieclip的类......不会给你一个错误??
-
类名总是大写,变量名不大写。这些都是强有力的约定。作为风格问题,仅对事件处理程序(即函数)使用后缀“处理程序”。如果要表示一个影片剪辑,请添加后缀 _mc。
-
Adam / Rendall:我很欣赏你的 cmets 风格,并将在未来考虑这一点 Eric:不,这不会引发错误。它工作正常,但我相信问题与“扩展”和“超级”代码有关,因为很明显 - 只需将孩子添加到电影剪辑中就可以正常工作!
标签: actionscript-3