AS3:将链接的 BitmapData 添加到舞台
我正在尝试将精灵添加到由位图数据制成的舞台,我从带有标识符 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建位图数据时,您将零的宽度和高度传递给位图数据。
这是不正确的。查看评论。
You are passing in a width and height of zero to your bitmapdata when creating it.
This is incorrect. See comments.
我不知道示例中的代码是否完整,但为了让您的指针显示您需要将其添加到舞台上。所以应该是:
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: