Actionscript 3、addChild 到舞台和 addEventListener 不能一起工作
我只想在舞台上添加我的库中的图像并在其上有一个事件侦听器,这样当我单击它时,它就会执行某些操作。 imgFromMyLib 已设置为我想要从我的库中获取的图像。请帮忙。做到这一点最简单的方法是什么?
import flash.display.Bitmap;
import flash.events.*;
import flash.display.Sprite;
function pwned(evt:MouseEvent):void
{
trace ("a");
}
var myImg:imgFromMyLib = new imgFromMyLib();
var myBitmap:Bitmap = new Bitmap(myImg);
myBitmap.addEventListener(MouseEvent.CLICK, pwned);
addChild(myBitmap);
I just wanna add an image from my library on the stage and have an event listener on it so when i click on it, it will do something. imgFromMyLib is already set to the image i want from my library. Please help. What is the easiest way to do this ?
import flash.display.Bitmap;
import flash.events.*;
import flash.display.Sprite;
function pwned(evt:MouseEvent):void
{
trace ("a");
}
var myImg:imgFromMyLib = new imgFromMyLib();
var myBitmap:Bitmap = new Bitmap(myImg);
myBitmap.addEventListener(MouseEvent.CLICK, pwned);
addChild(myBitmap);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个....
try this....
假设您尝试导入的符号是图形,并且是 BitmapData 的子类,则必须在其构造函数中传递其所需的尺寸:
Assuming that the symbol you're trying to import is a graphic, and so subclasses BitmapData, you must pass its required dimensions in it's constructor: