如何使用ActionScript 3.0更改Flash文档的背景?(How do I change the background of a Flash document using ActionScr

编程入门 行业动态 更新时间:2024-10-24 02:32:58
如何使用ActionScript 3.0更改Flash文档的背景?(How do I change the background of a Flash document using ActionScript 3.0?)

让我先说一下这个问题,我说我是一名.NET开发人员,只是帮助一个正在研究的项目的朋友。

我一直在网上寻找一些我觉得应该很简单的东西。 这就是我所拥有的:

标准Flash CS5文档,其中一层称为背景。 该文档与一个名为“Game”的类相关联,该类扩展了MovieClip。 我在调用'Initialize'方法后在'Game'类中执行一些逻辑。

我想在运行时将文档的背景颜色更改为其他颜色(例如,不同的颜色,渐变或图片)。 简单吧? 也许不会。 我无法弄明白。 一些.NET友好的灵魂可以解释如何解决这个问题吗?

Let me preface this question by saying that I am a .NET developer at heart, just helping a friend with a project he is working on.

I have been searching online for something that I think should be pretty simple. Here's what I have:

A standard Flash CS5 document with one layer called background. The document is associated with a class called 'Game' which extends MovieClip. I am executing some logic in the 'Game' class after calling an 'Initialize' method.

I want to change the background color of the document at runtime to something else (e.g., a different color, a gradient, or a picture). Simple, right? Maybe not. I can't figure it out. Can some .NET-friendly soul kindly explain how to fix this?

最满意答案

如果你想让背景改变颜色,而不是画它,javascript可能是解决这个问题的好方法。

你改变的将取决于嵌入代码,但你想要改变的参数是bgcolor。

在原型中,javascript看起来像这样:

$('yourFlashContainerId').down('[name="bgcolor"]').writeAttribute('value','#000000');

要在flash中绘制它,你可以这样做:

var bg:Sprite = new Sprite(); bg.graphics.beginFill(0x000000); bg.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight); bg.graphics.endFill(); bg.x = 0; bg.y = 0; addChildAt(bg,0);

这将绘制一个黑色背景的正方形(更改第2行的十六进制以更改颜色),将其大小设置为舞台的大小,将x和y设置为0,然后将其添加到显示堆栈的底部。

这两种方法中的任何一种都应该有效。

编辑:另一种方式:

您还可以将wmode参数设置为“透明”,并更改包含div背景颜色。

假设你的flash嵌入有以下内容:

<param name="wmode" value="transparent">

原型:

$('yourFlashContainerId').setStyle({'background-color':'#000'});

jQuery的:

$('#yourFlashContainerId').css({'background-color':'#000'});

本地:

document.getElementById('yourFlashContainerId').style.background-color="#000";

If you wanted the background to change color, and not have to draw it in, javascript might be a good solution for this problem.

what you change will depend on the embed code, but the param you'll want to change is bgcolor.

in prototype, the javascript would look something like this:

$('yourFlashContainerId').down('[name="bgcolor"]').writeAttribute('value','#000000');

to draw it in flash, you can do something like this:

var bg:Sprite = new Sprite(); bg.graphics.beginFill(0x000000); bg.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight); bg.graphics.endFill(); bg.x = 0; bg.y = 0; addChildAt(bg,0);

That will draw a square with a black background (change the hex on line 2 to change the color), set it's size to the size of the stage, set x and y to 0, then add it at the bottom of the display stack.

Either of those two methods should work.

Edit: yet another way:

You could also set the wmode param to "transparent", and change the containing div background color.

assuming your flash embed has the following:

<param name="wmode" value="transparent">

prototype:

$('yourFlashContainerId').setStyle({'background-color':'#000'});

jQuery:

$('#yourFlashContainerId').css({'background-color':'#000'});

native:

document.getElementById('yourFlashContainerId').style.background-color="#000";

更多推荐

本文发布于:2023-07-22 18:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   背景   文档   ActionScript   document

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!