使用javascript调用AS3全屏

时间:2011-11-29 10:17:06

标签: javascript flash actionscript-3 externalinterface

我有两个AS3功能。一个切换全屏,一个使用带有外部接口的javascript调用,只记录“Hello World”。

两者在浏览器中运行良好,但如果我尝试用javascript以相同的方式调用全屏功能,我会收到如下错误:

Error calling method on NPObject!

我用谷歌搜索了这个问题,但只是与相同的域访问有关,而且它与其他函数有关,它必须是其他的东西。

我做错了什么?

2 个答案:

答案 0 :(得分:4)

全屏模式只能通过用户输入设置。所以我很害怕从javascript调用它是不允许的。

  

响应鼠标单击或按键启动全屏模式   按用户按下;电影无法更改Stage.displayState   用户输入。 Flash运行时限制键盘输入全屏   模式。可接受的键包括终止的键盘快捷键   全屏模式和非打印键,如箭头,空格,Shift,   和Tab键。终止全屏模式的键盘快捷键是:   逃生(Windows,Linux和Mac),Control + W(Windows),Command + W.   (Mac)和Alt + F4。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#displayState

答案 1 :(得分:-2)

当然,您可以为在Web浏览器中运行的Flash影片启动全屏。但您必须在HTML代码中启用全屏模式...

请阅读此主题:

以下限制适用于在HTML页面中播放的SWF文件(不是那些使用独立Flash Player或未在AIR运行时中运行的文件):

* To enable full-screen mode, add the allowFullScreen parameter to the object and embed tags in the HTML page that includes the SWF file, with allowFullScreen set to "true", as shown in the following example:

  <param name="allowFullScreen" value="true" />
            ...
      <embed src="example.swf" allowFullScreen="true" ... >

  An HTML page may also use a script to generate SWF-embedding tags. You need to alter the script so that it inserts the proper allowFullScreen settings. HTML pages generated by Flash Professional and Flash Builder use the AC_FL_RunContent() function to embed references to SWF files, and you need to add the allowFullScreen parameter settings, as in the following:

  AC_FL_RunContent( ... "allowFullScreen", "true", ... )

* Full-screen mode is initiated in response to a mouse click or key press by the user; the movie cannot change Stage.displayState without user input. Flash runtimes restrict keyboard input in full-screen mode. Acceptable keys include keyboard shortcuts that terminate full-screen mode and non-printing keys such as arrows, space, Shift, and Tab keys. Keyboard shortcuts that terminate full-screen mode are: Escape (Windows, Linux, and Mac), Control+W (Windows), Command+W (Mac), and Alt+F4.

  A Flash runtime dialog box appears over the movie when users enter full-screen mode to inform the users they are in full-screen mode and that they can press the Escape key to end full-screen mode.
* Starting with Flash Player 9.0.115.0, full-screen works the same in windowless mode as it does in window mode. If you set the Window Mode (wmode in the HTML) to Opaque Windowless (opaque) or Transparent Windowless (transparent), full-screen can be initiated, but the full-screen window will always be opaque.

然后,您必须在ActionScript 3.0中创建一个函数以更改Stage.displaystate进行全屏显示。

要从JavaScript调用actionscript 3.0函数,可以使用ActionScript 3.0的ExternalInterface API。 请参阅Adobe帮助中的ExternalInterface类API说明。