让我先说一下这个问题,我说我是一名.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";更多推荐
发布评论