ActionScript BitmapData 内置到位图中?

发布于 2024-09-03 03:21:20 字数 741 浏览 0 评论 0原文

我使用 Loader 和 URLRequest 从互联网下载 .png 并将其添加到我的显示列表中。既然它已经是位图了,它是否已经内置了位图数据?或者我必须自己创建位图数据?

另外,为什么相同的跟踪语句在 displayImage 函数中输出 true 时却在 mouseMoveHandler 中返回 false?

    var imageLoader:Loader = new Loader();
    imageLoader.load(new URLRequest("http://somewebsite.com/image.png"));
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, displayImage);

    function displayImage(evt:Event):void
     {
     addChild(evt.target.content);
     addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

     trace(evt.target.content is Bitmap);  //outputs 'true'
     }

   function mouseMoveHandler(evt:MouseEvent):void
     {
     trace(evt.target.content is Bitmap);  //outputs 'false'
     }

i've used a Loader and URLRequest to download a .png from the internet and add it to my display list. since it's already a bitmap, does it have built in bitmap data already? or do i have to create the bitmap data myself?

also, why does the same trace statement return false in the mouseMoveHandler when it outputs true in the displayImage function?

    var imageLoader:Loader = new Loader();
    imageLoader.load(new URLRequest("http://somewebsite.com/image.png"));
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, displayImage);

    function displayImage(evt:Event):void
     {
     addChild(evt.target.content);
     addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

     trace(evt.target.content is Bitmap);  //outputs 'true'
     }

   function mouseMoveHandler(evt:MouseEvent):void
     {
     trace(evt.target.content is Bitmap);  //outputs 'false'
     }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

债姬 2024-09-10 03:21:20

快速搜索 AS3 文档告诉我 位图有一个 bitmapData 属性

您在每次跟踪中都会得到不同的结果,因为您正在跟踪不同的事物。尝试仅跟踪属性而不是“是位图”,以查看实际存储的内容。

您的第一个跟踪是跟踪事件,第二个跟踪是鼠标事件。您的 displayImage 函数是“加载程序完成处理程序”,因此目标将是 LoaderInfo 对象。在 LoaderInfo 对象中,target 指的是“与此 LoaderInfo 对象关联的加载的 DisplayObject”。但在 MouseEvent 中,目标会有所不同。您需要参考 文档对于每个事件来找出目标是什么。

另外,我认为您需要将鼠标移动事件侦听器添加到舞台上,否则它将无法工作,例如

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

A quick search of the AS3 docs tells me that Bitmap has a bitmapData property.

You are getting different rusults in each trace because you are tracing different things. try just tracing the property rather that "is Bitmap", to see what is actually stored there.

Your first trace you are tracing an Event, your second a MouseEvent. Your displayImage function is a "Loader Complete handler", so target will be a LoaderInfo object. In a LoaderInfo object, target refers to "The loaded DisplayObject associated with this LoaderInfo object". But in a MouseEvent the target will be different. You will need to refer to the docs for each event to find out what the target will be.

Also, I think you will need to add the mouse move event listener to the stage, or it wont work e.g.

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文