2011-12-13 79 views
0

在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); 
    } 
} 
+0

不确定你遇到的问题,但你应该看看AS3编码约定http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions围绕变量和类的大小写名。 – 2011-12-13 22:09:57

+0

我不认为这会工作,因为你不能将参数传递给mcButtonPlay,而它扩展了一个扩展了movieclip的类......不会给你一个错误? – Eric 2011-12-13 22:26:05

+0

总是要大写类名和大写变量名。这些都是强大的惯例。 作为一种风格,仅为事件处理程序(即函数)使用后缀“处理程序”。如果您想表示一个MovieClip,请添加后缀_mc。 – 2011-12-14 05:02:41

回答

0

管理通过交换超强修复它和周围添加子逻辑:

public class mcButtonPlay extends navigationButtonHandler { 
    public function mcButtonPlay(Parent:MovieClip,Text:String,GameImage:BitmapData) { 
     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 
     }      
     super(Text); 
    } 
} 

不知道为什么,但!

0
 this.addChild(ImageBitMap); // * * * This doesn’t show 
     Parent.addChild(ImageBitMap); // Works just to test the image 

有了这个代码,ImageBitMap是被从'this'中删除并放入'Parent',所以你永远不会在'this'中看到它。

删除第二行,并告诉我它是否仍在工作。

编辑:

您是否将btPlay添加到舞台或显示层级?

例如。

btPlay = new mcButtonPlay(this,"ClickMe",GameImage); 
this.addChild(btPlay); 
0
public class navigationButtonHandler extends MovieClip { 
    public function navigationButtonHandler(Text:String) { 
     ChangeButtonTargetText(Text); 
     Parent.addChild(this); //<--------???? 
    } 
} 

其中在从提问复制上面的代码段确实来自Parent?看起来navigationButtonHandler类永远不会被添加到舞台上,因为它没有得到Parent?所以扩展类也永远不会添加到舞台上,因此如果将它添加到mcButtonPlay类中,它将永远不会显示。
您的扩展构造函数会传递Parent参数,但基类不会。这对我来说似乎很奇怪,不应该编译。或者你在幕后做了一些静态的事情?

然后按照注释中提到的大小写方式工作。如果您遵循常规惯例,阅读和查找错误真的更容易!