Sample name: ActionScript3 comunication with JavaScript. This works only on webserver. Author: Eriks Kruze. Developed with: FleshDevelop v3, Flex SDK 3.
Nosaukums: AS3 komunikācija ar JavaScript. Strādā tikai no webservera.
Download source: as3_and_js_comunication.rar
            // --- as3 part ---
            package 
            {
                import flash.display.Sprite;
                import flash.events.Event;
                import flash.events.MouseEvent;
                import flash.external.ExternalInterface; // this class is needed to communicate with JS
                
                [SWF(width="70", height="40", frameRate="31")]
                
                public class test_js extends Sprite
                {
                    function test_js()
                    {
                        var button:Sprite = new Sprite();
                        button.graphics.lineStyle(1, 0xff0000, 1);
                        button.graphics.beginFill(0xff0000, 0.5);
                        button.graphics.drawRect(10, 10, 50, 20);
                        button.graphics.endFill();
                        button.addEventListener(MouseEvent.CLICK, run_js);
                        addChild(button);
                    }
                    
                    // function that comunicate with JavaScript
                    public function run_js(myEvent:MouseEvent):void
                    {
                        var result:Boolean = ExternalInterface.call("test_js"); // test_js is JavaScript function name in HTML
                    }
                }
                
            }

            --- html part ---
            <html>
            <head>
            </head>
            <body>

            <div>        
                <script type="text/javascript" >
                function test_js()
                {
                    if(document.getElementById('test_js_status').value==1)
                    {
                        document.getElementById('test_js_status').value=0
                    }
                    else
                    {
                        document.getElementById('test_js_status').value=1
                    }
                }
                </script>    

                <embed src="test_js.swf" quality="high" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" height="40" width="70" hspace="0" vspace="0" border="0" wmode="transparent" allowscriptaccess="allways" play="true" loop="true" bgcolor="" menu="true" />
                <input type="text" name="test_js_status" id="test_js_status" />
            </div>

            </body>
            </html>