googleAdsense_widever


mx:html call and receive javascript function FLEX/Flash

interaction with js and as.
http://blog.everythingflex.com/2008/02/25/air-actionscript-javascript-bridge/
StageWebViewBridge 라는 library 를 사용할 필요 없이, 기본 HTML 컴포넌트에 위 소스 대로 사용하면 된다.
JavaScript

<html>
    <script language="Javas-ript">
        function calledFromAS() {
            alert('Hello from ActionScript');
        }
        </script>
    <body>
        <input type="button"
            value="Call ActionScript from JavaScript"
            onclick="calledFromJSHandlerFunction()" />
        <br />
        <input type="button"
            value="Normal JavaScriptAlert"
            onclick="alert('Hello from JavaScript')">
    </body>
</html>

ActionScript

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="init()">
    <mx:Script>
    <![CDATA[
        private var calledFromJSHandlerFunction:Function = calledFromJSHandler;
        private function init():void{
            html.addEventListener(Event.HTML_DOM_INITIALIZE, domInitialized);
            html.location = "htmlwithJS.html";
        }
        private function domInitialized(event:Event):void{
            html.htmlLoader.window.calledFromJSHandlerFunction = calledFromJSHandlerFunction;
        }
        private function calledFromJSHandler():void {
            mx.controls.Alert.show("ActionScript called from JavaScript", "Alert");
        }
        private function doHTMLAlert( ):void {
            html.htmlLoader.window.calledFromAS();
        }
    ]]>
    </mx:Script>
    <mx:Button id="alertBtn" label="Call JavaScript from ActionScript"
        click="doHTMLAlert()" x="137" y="10"/>
    <mx:HTML id="html" x="137" y="40" width="339"/>
    <mx:Label x="10" y="12" text="Normal MXML Button"/>
    <mx:Label x="28" y="38" text="HTML component"/>
</mx:WindowedApplication>


덧글

댓글 입력 영역


공지

어서오십시오.
트위터 : @FCliver
기저심리학 : 네이버카페
카카오톡 : FCliver
페이스북 : Fredric Cliver

통계 위젯 (화이트)

40
50
288879

접속자 위치