欲按钮的图形动态地加载到所述按钮(上和以上)的每个帧中一个MC。 在每个帧我有一个影片剪辑(帆布canvas_over)
I want to dynamically load the graphic of the button into an mc inside each frame of the button (up and over). Inside each frame I have a movie clip (canvas and canvas_over)
绿框是按钮对象(header_btn):
The green box is the button object (header_btn):
这是我的code:
var hLoader:Loader = new Loader();
hLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hLoaded);
hLoader.load(new URLRequest("https://p.xsw88.cn/allimgs/daicuo/20230909/106.png"));
function hLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_btn.canvas.addChild(image);
}
var hoLoader:Loader = new Loader();
hoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hoLoaded);
hoLoader.load(new URLRequest("https://p.xsw88.cn/allimgs/daicuo/20230909/107.png"));
function hoLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_btn.over_canvas.addChild(image);
}
我得到的错误是:
The error I get is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-78()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-77()
编辑 - 解决:
header_canvas
和 header_canvas_over
被放置在舞台上。 header_canvas_over
放置在 header_canvas
。
Edit - Solved:
header_canvas
and header_canvas_over
are placed on stage. header_canvas_over
is placed over header_canvas
.
code:
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
var hLoader:Loader = new Loader();
hLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hLoaded);
hLoader.load(new URLRequest("https://p.xsw88.cn/allimgs/daicuo/20230909/106.png"), context);
function hLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_canvas_up.addChild(image);
}
var hoLoader:Loader = new Loader();
hoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, hoLoaded);
hoLoader.load(new URLRequest("https://p.xsw88.cn/allimgs/daicuo/20230909/107.png"), context);
function hoLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
header_canvas_over.addChild(image);
header_canvas_over.visible = false;
header_btn.addEventListener(MouseEvent.MOUSE_OVER, onHover);
function onHover(event:Event):void {
header_canvas_over.visible = true;
}
header_btn.addEventListener(MouseEvent.MOUSE_OUT, onOut);
function onOut(event:Event):void {
header_canvas_over.visible = false;
}
}
这将是很好但如果AS3允许按钮,包含对象。 :/
It would be nice though if as3 allowed for buttons to contain objects. :/
推荐答案
使用SimpleButton类是从的DisplayObject,不是的DisplayObjectContainer延长。这意味着,你不能访问某个按钮的时间轴那样的对象,也不能添加或删除的孩子。
The SimpleButton class is extended from DisplayObject, not DisplayObjectContainer. That means that you can't access objects on a button's timeline in that way, nor can you add or remove children.
有关你在想什么做它可能是值得创建扩展影片剪辑的自定义按钮类。你不得不增加code自己的用户交互的状态之间移动,但你会得到更多的控制状态之间的视觉过渡,以及他们的内容。
For what you're wanting do do it might be worth creating a custom button class that extends MovieClip. You'd have to add code yourself for moving between the states on user interaction, but you would get a lot more control over the visual transition between states as well as the content of them.
相关推荐
最新文章