A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] externalInterface not working?

  1. #1
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186

    resolved [RESOLVED] externalInterface not working?

    I have a html unordered list as a menu. I want an image in the flash header to change when user clicks different menu items.

    Here is the javascript in the header of my html page:
    Actionscript Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    function findSWF(movieName) {
     if (navigator.appName.indexOf("Microsoft")!= -1) {
       return window[movieName];
     } else {
       return document[movieName];
     }
    }

    function containerToFlash(str) {
     findSWF("sample").containerToFlash(str);
    }
    // -->
    </script>

    The code embedding the swf:

    <object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" width="738" height="245" id="sample">
    <param name="movie" value="http://www.monikaviktoria.com/test/wp-content/themes/lace-and-moss/flash/sample.swf" />
    <param name="wmode" value="transparent" />
    <param name="scale" value="noscale" />
    <param name="allowScriptAccess" value="always" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="http://www.monikaviktoria.com/test/wp-content/themes/lace-and-moss/flash/sample.swf" width="738" height="245" id="sample">
    <param name="wmode" value="transparent" />
    <param name="scale" value="noscale" />
    <param name="allowScriptAccess" value="always" />
    <!--<![endif]-->
    <p>Alternative content</p>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
    </object>


    The 'onclick' function on html link:
    Actionscript Code:
    <li onclick="javascript:containerToFlash('Hello')"><a class="nav_title" href="#">home</a><br /><span class="sub">begin</span></li>

    The actionscript in flash:
    Actionscript Code:
    import flash.external.ExternalInterface

    function flashFunction(str:String):Void {
        if (str == undefined) {
            _root.myText.text="undefined";
        } else {
            _root.myText.text = str;
        }
    }

    ExternalInterface.addCallback("containerToFlash", null, flashFunction);

    Dynamic text box on stage with instance name 'myText' - always reads 'undefined'.

    Any ideas anyone? I've scowered the internet for examples, but they all differ from each other, so I can't pinpoint what I'm doing wrong. I hope someone here can see...

    Thanks.
    Last edited by aneemal; 09-26-2010 at 04:36 PM.

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186
    For anyone else out there having difficulties with this: try this! This is the only working example I have found... and I searched a lot! I used this code and changed it as per my requirements and it works fine. I think it may be the inclusion of this:
    Actionscript Code:
    <body onLoad='findSWF("movieName");'>
    that makes it work.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center