Actionscript3-使用按钮在图像之间切换



我正在Flash builder中打开一个新的flex项目,我正在尝试制作一个有3个按钮的界面,"猫"、"狗"one_answers"鸟"。当按下每个按钮时,我希望屏幕底部有一个图像框来填充适当的动物图像。

我很难弄清楚如何在AS3中显示图像。有人能帮我指明正确的方向吗?

最简单的方法之一是,如果你不介意你的swf嵌入三个图像:

嵌入代码

[Embed(source="/../assets/cat.jpg")]
static private const Cat:Class;
[Embed(source="/../assets/dog.jpg")]
static private const Cat:Class;
[Embed(source="/../assets/bird.jpg")]
static private const Cat:Class;

容器初始化

private var imageBox:Sprite = new Sprite;
// initialize imagebox position/chose parent here, for instance:
container.addChild(imageBox);

cat按钮点击处理程序

imageBox.removeChildren();
imageBox.addChild(new Cat);

狗按钮点击处理程序

imageBox.removeChildren();
imageBox.addChild(new Dog);

鸟按钮点击处理程序

imageBox.removeChildren();
imageBox.addChild(new Bird);

我假设你的项目有"资产"&"src"目录,分别包含您的图像和您的as3代码

最新更新