AS3:将链接的 BitmapData 添加到舞台

发布于 2024-12-09 23:22:21 字数 1100 浏览 0 评论 0原文

我正在尝试将精灵添加到由位图数据制成的舞台,我从带有标识符 pointerGraphic 的库链接到,这是我的代码:

Pointer.as

package com.George.BMIapp
{
    import pointerGraphic;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.geom.Rectangle;
    import flash.display.Bitmap;

    public class Pointer extends Sprite
    {

        const graphic:Bitmap = new Bitmap(new pointerGraphic(0,0));

        private var _pointer:Sprite = new Sprite();

        public function get sprite():Sprite
        {
            return this;
        }

        public function Pointer(y:int, minX:int, maxX:int)
        {
            _pointer.addChild(graphic);
            addChild(_pointer);
            _pointer.x = minX;
            _pointer.y = y;
        }

    }

}

并初始化它像这样:

import com.George.BMIapp.Pointer;

//Constants for pointer movement
var POINTER_MIN_X:int = 68;
var POINTER_MAX_X:int = 283;

var heightPointer:Pointer = new Pointer(371, POINTER_MIN_X, POINTER_MAX_X);

然而舞台上什么也没有出现,但没有错误(我处于启用调试的严格模式)。

I'm trying to add a sprite to a stage made from bitmapData I link to from the library with the identifier pointerGraphic, here's my code:

Pointer.as

package com.George.BMIapp
{
    import pointerGraphic;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.geom.Rectangle;
    import flash.display.Bitmap;

    public class Pointer extends Sprite
    {

        const graphic:Bitmap = new Bitmap(new pointerGraphic(0,0));

        private var _pointer:Sprite = new Sprite();

        public function get sprite():Sprite
        {
            return this;
        }

        public function Pointer(y:int, minX:int, maxX:int)
        {
            _pointer.addChild(graphic);
            addChild(_pointer);
            _pointer.x = minX;
            _pointer.y = y;
        }

    }

}

and I initialise it like so:

import com.George.BMIapp.Pointer;

//Constants for pointer movement
var POINTER_MIN_X:int = 68;
var POINTER_MAX_X:int = 283;

var heightPointer:Pointer = new Pointer(371, POINTER_MIN_X, POINTER_MAX_X);

Yet nothing appears on the stage, yet there are no errors (I'm in strict mode with debugging enabled).

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

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

发布评论

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

评论(2

空名 2024-12-16 23:22:21

创建位图数据时,您将零的宽度和高度传递给位图数据。

这是不正确的。查看评论。

You are passing in a width and height of zero to your bitmapdata when creating it.

This is incorrect. See comments.

野稚 2024-12-16 23:22:21

我不知道示例中的代码是否完整,但为了让您的指针显示您需要将其添加到舞台上。所以应该是:

var heightPointer:Pointer = new Pointer(371, POINTER_MIN_X, POINTER_MAX_X);
addChild(heightPointer);

I don't know if your code is complete or not in the example, but for your pointer to show you need to add it to the stage. So it should be:

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