Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   не работает ExternalInterface (http://www.flasher.ru/forum/showthread.php?t=121050)

PgeorgyV 06.02.2009 12:24

не работает ExternalInterface
 
Все перепробовал, ничего не помогает, вот выложил пример из документации, firebug выдает thisMovie("ExternalInterfaceExample").sendToActionScript is not a function, ткните пальцем, где ошибка или дайте рабочий примерчик плиз
Код:

<html lang="en">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>ExternalInterfaceExample</title>
 <script language="JavaScript">
    var jsReady = false;
    function isReady() {
        return jsReady;
    }
    function pageInit() {
        jsReady = true;
        document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
    }
    function thisMovie(movieName) {
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName];
        } else {
            return document[movieName];
        }
    }
    function sendToActionScript(value) {
        thisMovie("ExternalInterfaceExample").sendToActionScript(value);
    }
    function sendToJavaScript(value) {
        document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
    }
 </script>
 </head>
 <body onload="pageInit();">
 
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            id="ExternalInterfaceExample" width="500" height="375"
            codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
        <param name="movie" value="ExternalInterfaceExample.swf" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#869ca7" />
        <param name="allowScriptAccess" value="sameDomain" />
        <embed src="ExternalInterfaceExample.swf" quality="high" bgcolor="#869ca7"
            width="500" height="375" name="ExternalInterfaceExample" align="middle"
            play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
            type="application/x-shockwave-flash"
            pluginspage="http://www.macromedia.com/go/getflashplayer">
        </embed>
    </object>
 
    <form name="form1" onsubmit="return false;">
        <input type="text" name="input" value="" />
        <input type="button" value="Send" onclick="sendToActionScript(this.form.input.value);" /><br />
        <textarea cols="60" rows="20" name="output" readonly="true">Initializing...</textarea>
    </form>
 
 </body>
 </html>

Код AS3:

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.text.TextFieldType;
    import flash.text.TextFieldAutoSize;
 
    public class ExternalInterfaceExample extends Sprite {
        private var input:TextField;
        private var output:TextField;
        private var sendBtn:Sprite;
 
        public function ExternalInterfaceExample() {
            input = new TextField();
            input.type = TextFieldType.INPUT;
            input.background = true;
            input.border = true;
            input.width = 350;
            input.height = 18;
            addChild(input);
 
            sendBtn = new Sprite();
            sendBtn.mouseEnabled = true;
            sendBtn.x = input.width + 10;
            sendBtn.graphics.beginFill(0xCCCCCC);
            sendBtn.graphics.drawRoundRect(0, 0, 80, 18, 10, 10);
            sendBtn.graphics.endFill();
            sendBtn.addEventListener(MouseEvent.CLICK, clickHandler);
            addChild(sendBtn);
 
            output = new TextField();
            output.y = 25;
            output.width = 450;
            output.height = 325;
            output.multiline = true;
            output.wordWrap = true;
            output.border = true;
            output.text = "Initializing...\n";
            addChild(output);
 
            if (ExternalInterface.available) {
                try {
                    output.appendText("Adding callback...\n");
                    ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
                    if (checkJavaScriptReady()) {
                        output.appendText("JavaScript is ready.\n");
                    } else {
                        output.appendText("JavaScript is not ready, creating timer.\n");
                        var readyTimer:Timer = new Timer(100, 0);
                        readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                        readyTimer.start();
                    }
                } catch (error:SecurityError) {
                    output.appendText("A SecurityError occurred: " + error.message + "\n");
                } catch (error:Error) {
                    output.appendText("An Error occurred: " + error.message + "\n");
                }
            } else {
                output.appendText("External interface is not available for this container.");
            }
        }
        private function receivedFromJavaScript(value:String):void {
            output.appendText("JavaScript says: " + value + "\n");
        }
        private function checkJavaScriptReady():Boolean {
            var isReady:Boolean = ExternalInterface.call("isReady");
            return isReady;
        }
        private function timerHandler(event:TimerEvent):void {
            output.appendText("Checking JavaScript status...\n");
            var isReady:Boolean = checkJavaScriptReady();
            if (isReady) {
                output.appendText("JavaScript is ready.\n");
                Timer(event.target).stop();
            }
        }
        private function clickHandler(event:MouseEvent):void {
            if (ExternalInterface.available) {
                ExternalInterface.call("sendToJavaScript", input.text);
            }
        }
    }
}


tikhop 06.02.2009 13:27

а если попробовать сделать функцию public (receivedFromJavaScript)?

CEBEP 06.02.2009 13:41

кажется ExternalInterface не работает на локальной машине, только в интырнете

silin 06.02.2009 14:40

у меня пример работает (FF3.1b2, IE7)

PgeorgyV 06.02.2009 15:20

да, локально не работает

dimarik 06.02.2009 15:52

У меня работaет локально. IE7. Но пришлось сходить сюда

silin 06.02.2009 16:33

не уверен на 100%, но разрешение на доступ к локальным файлам вроде бы не причем

специально удалил все разрешения из C:\Documents and Settings\USER\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust
и перекомпилил с useNetwork = true
все равно работает..

hipot 06.02.2009 23:33

локально не работает,
базовая работа с ExternalInterface

darksranger 07.02.2009 00:13

я криворукий ? почему у меня работает локально !
opera\apache 2.2

спекцально залез в help, создал новый прожкт, запустил, вуаля .... все рабоает

единственно когда я делал проэкт с externom мне пришлось отказатся от swfobject так как почему так и не получилось получить в разумительную работу при вставке через него но это мелочи

вобщем меня беспокоит только одно, а именно для кого сделали TRACE ? что так сложно отследить ошибку ? ааа поражают темы аля " неработает то что на самом деле работает, просто у меня руки кривые и трэйс религия не позволяет использовать "

hipot 07.02.2009 00:52

Цитата:

я криворукий ? почему у меня работает локально !
opera\apache 2.2
имелось в виду, что не работает, если октрыть html-страницу в браузере с жесткого диска, а не по схеме http://somehost/fileWithflash.html


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

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