Aide - Recherche - Membres - Calendrier
Version complète : Apollo et javascript
Centre de Formation Flash - Forums Adobe Flash > Rich media et intégration > Flex
neo-lao
Salut,


vous avez réussi à accéder à une variable javascript depuis actionscript ?
Je fais référence à la documentation qui donne un exemple de code:
CODE
var html:HTMLControl = new HTMLControl();
html.width = 300;
html.height = 300;
html.addEventListener(Event.COMPLETE, completeHandler);
var xhtml:XML =
     <html>
         <script>
             foo = 333;
             function test() {
                 return "OK.";
             }
         </script>
         <body>
             <p id="p1">Hi.
         </body>
     </html>;
html.loadString(xhtml.toString());

function completeHandler(e:Event):void {
     trace(html.window.foo); // 333
     trace(html.window.document.getElementById("p1").innerHTML); // Hi.
     trace(html.window.test()); // OK.
}


Je n'arrive pas à faire marcher l'exemple
neo-lao
bon, en fin de compte, j'ai réussi.

c'était juste la function qui m'empêchait de compiler icon_razz.gif
jeanphilippe
tu peux nous faire un exemple neo ?
merci icon_biggrin.gif
neo-lao
un exemple ?
heu .. j'peux filer le mxml :

CODE
<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" title="Test" creationComplete="initApp()">
    <mx:Script><![CDATA[
        import flash.events.Event;
        import mx.controls.Alert;
        
        private function initApp():void
        {
            toto.htmlControl.addEventListener(Event.COMPLETE, _completeHandler);
            var xhtml:XML = XML("<html>"+
                     "<script>"+
                         "foo = 333;"+
                         "function test() {"+
                             "return 'OK';"+
                         "}"+
                     "</script>"+
                     "<body>"+
                         "<p>Hi.</p>"+
                     "</body>"+
                 "</html>");
            toto.htmlControl.loadString(xhtml.toString());
        }
    
        private function _completeHandler(e:Event):void {
            Alert.show(toto.htmlControl.window.foo);
            Alert.show(toto.htmlControl.window.test());
        }

    ]]></mx:Script>
    <mx:HTML id="toto" height="100%" width="100%" location=""/>
</mx:ApolloApplication>


Ca marche en compilant ça.
jeanphilippe
oui effectivement ça compile smile.gif
Ceci est une version "bas débit" de notre forum. Pour voir la version complète avec plus d'informations, la mise en page et les images, veuillez cliquer ici.
Invision Power Board © 2001-2009 Invision Power Services, Inc.