使用 ActionScript 3.0 调整窗口大小
有没有办法使用 Actionscript 或其他方法调整整个 Flash 项目的大小?
我创建了一个 1024x768 Flash CS3 应用程序,但在仔细检查规格后,我现在意识到它必须是 800x600。 我不想手动缩小所有内容,而是想调整窗口大小,就像有人拖动外边缘一样。 或者添加一个允许在 1024x768 和 800x600 之间切换的按钮。 这可能吗?
我的意思是这样的:
stage.stageWidth = 800;
stage.stageHeight = 600;
Is there any way to resize an entire Flash project using Actionscript or some other method?
I have created a 1024x768 Flash CS3 application, but upon closer inspection of the specifications, I now realise it has to be 800x600. Instead of manually making everything smaller, I'd like to resize the window as if someone were dragging the outside edge. Or perhaps add a button that allows switching between 1024x768 and 800x600. Is this possible?
I mean something like this:
stage.stageWidth = 800;
stage.stageHeight = 600;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,stageWidth 和 stageHeight 是只读的,尽管有文档。 但是,如果 SWF 嵌入到网页中,则更改其元素宽度和高度将更改舞台大小,并且 scaleMode 将确定如何处理。 我的 Enjoy3D 网站 上的所有 SWF 都会在窗口大小调整时执行此操作...
Yes stageWidth and stageHeight are readonly, despite the docs. But if the SWF is embedded in a web page, then changing its element width and height will change the stage size and scaleMode will determine how that is handled. All the SWFs at my Enjoy3D web site do this on window resize...
如果您愿意,您只需编辑 SWF 的 HTML 包装器并判断新尺寸(我担心)和光栅化媒体是否会在缩小时出现像素化。 最好缩小所有内容,即使您不想这样做。
如果您确实需要在 Flash 中执行此操作,请使用 flash.external 包的ExternalInterface 类来调用 HTML 中的 JavaScript 函数。 确保您的 swf 位于 div 内并设置为 div 高度和宽度的 100%。 现在,您只需通过 JavaScript 通过 Actionscript 更改 div 的大小。
确保您已按照您想要的方式设置 stage.scaleMode。
干杯
If you wanted you could merely edit the HTML wrapper for your SWF and tell if the new dimensions, though I fear and rasterized media will be pixelated even when shrinking. It is best to shrink everything, even though you don't want to.
If you just really need to do it in flash use the ExternalInterface class of the flash.external package to make a call to a JavaScript function in your HTML. Make sure your swf is inside a div and set to 100% of the div's height and width. Now you merely change the size of the div via JavaScript via Actionscript.
Make sure that you have stage.scaleMode set the way you want it.
Cheers
您无法从 Actionscript 更改舞台宽度和高度,这些属性是只读的。
在编译 swf 之前,您不能将舞台属性的大小(我假设您在这里使用 Flash)设置为 800 x 600 吗?
You can't change the stage width and height from Actionscript, those properties are read-only.
Couldn't you just set the size of the stage properties (I assume you're using Flash here) to 800 by 600 before you compile your swf?
或者如果您有一个纯 ActionScript 项目,无法执行 FlexGlobals 或 Application,您可以从主 ActionScript 文件(Sprite)执行以下操作(请注意,在执行此操作之前必须初始化阶段)
Or if you have a pure ActionScript project, whereby you cannot do FlexGlobals or Application, you could from your main actionscript file (Sprite) execute the following (note that stage must be initialised before doing this)