dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Using navigateToURL to run javascript?

  1. #1
    Junior Member
    Join Date
    Sep 2003
    Location
    Gold Coast, Australia
    Posts
    12

    Using navigateToURL to run javascript?

    I'm not sure I'm doing this right...

    I'm trying to have a simple browser window pop-up when the user clicks on an element in my page. This is what I'm working with at the moment:

    In the flash document

    Code:
    import flash.net.*;
    
    ...
    
    imageLink = thumbnailLink + "big.html";
    var launcher:String = "javascript:Launch('" + imageLink + "')"
    trace(launcher);
    navigateToURL(new URLRequest(launcher), 'seetoys');
    and then in the html page that the flash is embedded in:

    Code:
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- Begin 
    function Launch(page) { 
    OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=550,height=250"); 
    } 
    // End --> 
    </SCRIPT>
    now the trace(launcher) is returning javascript:Launch('thumb1big.html') which is prettyt much what I expected it to. However when I test the movie in a browser it isn't doing anything at all when I click on the button.

    Now my question is, have I missed some new way to run a javascript from flash (I used to use getURL in 2.0 but am trying to learn 3.0 as I go along)

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Use ExternalInterface

    ExternalInterface.call ("javascriptfunctionname","mypage.html");

    In the parameters for publishing

    'allowScriptAccess','always',

    You can only test this on your server not locally.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Sep 2003
    Location
    Gold Coast, Australia
    Posts
    12
    ok I'm getting real close now, just having a slight problem sending more than one parameter to the javascript function. I have the following in my flash file:

    Code:
    var windowHeight:Number;
    ....
    windowHeight = 600;
    ...
    trace(windowHeight)
    ExternalInterface.call("Launch", imageLink, windowHeight);
    now the windowheight is determined by a switch statement, but at the end when I call a trace on it I get the expected number, so all is good, however I have the following in my html document:

    Code:
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- Begin 
    function Launch(page, windowHeight) {
    var features = "width=510, height=" + windowHeight + ",toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no";
    alert(windowHeight);
    OpenWin = this.open(page, "CtrlWindow", features); 
    } 
    // End --> 
    </SCRIPT>
    and the alert(windowHeight) is returning "undefined" the first parameter is being sent fine and is working. (note: the alert is just there so I coudl find out why it wasnt working) so does anyone know why the windowHeight variable isn't being sent to the javascript function?

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Try this:
    javascript
    PHP Code:
    <script language="javascript" type="text/javascript">
    //<![CDATA[
    <!--
    function 
    openWindow(newWindow){
          
    window.open(newWindow"myFile""windowHeight, width=500, scrollbars=no, top=0");
    }
    -->
    //]]>
    </script
    code in the movie
    var windowHeight:Number=600;
    newWindow = String (ExternalInterface.call ("openWindow", "newwindow.html","windowHeight"));

    You need to modify for your purpose of course.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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