Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   вызвать Flash функцию с помощью js (http://www.flasher.ru/forum/showthread.php?t=141105)

greegreeman 16.06.2010 14:07

вызвать Flash функцию с помощью js
 
Всем привет. Вопрос такой. Есть флэшка, в ней функции ) хочу дернуть их из жабаскрипт. Делаю кнопку в штмл обертке к флэшке:
PHP код:

<input type="button" onClick="callExternalInterface()" value="Play" /></form

как мне дальше поступить, чтобы вызвать функцию из флэш?

Партизан 16.06.2010 14:10

зарегистрировать в флешке функцию для JS
Код AS3:

ExternalInterface.addCallback("func", as3func)

дальше можно вызывать ее из JS

Хемуль 16.06.2010 14:32

2 greegreeman:
Разберитесь в примерах.

greegreeman 16.06.2010 16:00

Посмотрел help ). Вроде все понятно. Но не получилось вызвать. пишу в html:
PHP код:

function playVideo() {
//alert("hello");
thisMovie("myFlashContent").playVideo();
}
<
input type="button" onClick="playVideo()" value="Play" /> 

во флэшке:
Код AS3:

ExternalInterface.addCallback("playVideo", receivedFromJavaScript);
private function receivedFromJavaScript():void
        {
                trace("Hello World");
        }


Партизан 16.06.2010 16:21

Вызывать нужно
Код:

function playVideo() {
document.getElementByID("myFlashContent").playVideo();
}

где myFlashContent это id тега object или embed вашей флешки

greegreeman 16.06.2010 17:27

Партизан, вызвал как вы говорите - все равно не работает. даже уже и не знаю в чем ошибку искать...

Добавлено через 23 минуты
приведу код из флэшки:
Код AS3:

if (ExternalInterface.available) {
try {
        ExternalInterface.addCallback("playVideo", receivedFromJavaScript);                               
} catch (error:SecurityError) {
        trace("A SecurityError occurred: " + error.message + "\n");
} catch (error:Error) {
        trace("An Error occurred: " + error.message + "\n");
}
        } else {
                trace("External interface is not available for this container.");
        }


Хемуль 16.06.2010 18:04

2 greegreeman:
А что получится, если в JavaScript написать:
Код:

alert(document.getElementByID("myFlashContent").playVideo)

Партизан 16.06.2010 18:05

html покажите
receivedFromJavaScript - а там что?

кстати ошибся немного document.getElementById

greegreeman 16.06.2010 18:33

показываю весь html:

Код:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <head>
                <title></title>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


                <script language="JavaScript">
                                           
                        function test() {
                                //alert("hello");
                        //thisMovie("myFlashContent").test();
                                document.getElementById("myFlashContent").test();                                       
                            }
                </script>


                <script type="text/javascript" src="swfobject.js">
                        swfobject.registerObject("myFlashContent", "9.0.0");                                                                       
                                                       
                </script>
       
        </head>
        <body>
                <div>
                        <object classid="тут был classid" width="500" height="400" id="myFlashContent" name="TestExternalInterface">
                                <param name="movie" value="TestExternalInterface.swf" />
                                <param name="allowfullscreen" value="true" />
                <param name="allowScriptAccess" value="always" />
                                <param name="flashvars"/>
                                <!--[if !IE]>-->
                                <object type="application/x-shockwave-flash" data="TestExternalInterface.swf" width="500" height="400">
                                        <param name="allowfullscreen" value="true" />
                    <param name="allowScriptAccess" value="always" />
                                        <param name="flashvars"/>
                                <!--<![endif]-->
                                        <a href="http://www.adobe.com/go/getflashplayer">
                                                <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                                        </a>
                                <!--[if !IE]>-->
                                </object>
                                <!--<![endif]-->
                        </object>
                </div>               

                <input type="button" onclick="test()" value="Test" />               
                               

        </body>
</html>

на стороне флэш:
Код AS3:

 
private function init():void
{
        trace("ExternalInterface.available " + ExternalInterface.available)
        if (ExternalInterface.available) {
                try {
                        ExternalInterface.addCallback("test", needToCall);
                } catch (error:SecurityError) {
                trace("A SecurityError occurred: " + error.message + "\n");
                } catch (error:Error) {
                        trace("An Error occurred: " + error.message + "\n");
                }
                        } else {
                                trace("External interface is not available for this container.");
                        }
 
        //ExternalInterface.addCallback("test", flashFunc);
        trace("I am here");
}
 
private function needToCall():void
{
      trace("!!!!!!!!!!!!!!!!!!!!!!!!!!");
}


Партизан 16.06.2010 18:46

ок, и как trace отлавливаешь из html?


Часовой пояс GMT +4, время: 11:36.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.