A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: _root in as3

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    6

    _root in as3

    Hi,

    I'm new to as3. I am trying to convert a script from as2 to as3.

    the code that I am struggling with is as follows:

    getURL('javascript:SetSliderValue(' + _root.cnt_txt.text + ')');


    I've converted it to:

    var request: URLRequest = new URLRequest('javascript:SetSliderValue('+ _root.cnt_txt.text +')');
    navigateToURL(request, "_blank");

    But it doesn't link as I would hope.

    I can't work out how the _root function should be revised


    Any suggestions/ corrections

    thanks

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Try root (without _), but use with caution.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Where is that line of code written, on the main timeline or in a movieclip?
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    Junior Member
    Join Date
    Sep 2008
    Posts
    6
    Hi,

    I've now made the scrip produce the correct code by removing the _root part altogether (thanks for your help), but it still doesn't work.

    The as2 version seems to put the url and 'press enter' for want of a better description, whereas the as3 version seems to put the utl into the browser, but doesn't make it press the enter key.

    I'm not surre if either script actually presses the enter key, but hopefully you can understand what I mean.

    The as3 script is in a movie clip, in layer1: frame1.

    The as2 script seems to be attached to a symbol definition, but I'm not if this is different to being part of the layer1:frame1 part of the script


    I hope this makes sense and thanks for helping so far

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Although some browsers will accept javascript interaction from flash like that, you are better off using ExternalInterface, as that's what it was designed for.

    Your code would look something like this:
    Code:
    import flash.external.ExternalInterface;
    if (ExternalInterface.available){
      ExternalInterface.call('SetSliderValue', cnt_txt.text);
    }//else trace an error or something so you know what went wrong.
    Note that you must test this on a server, and you must add "allowScriptAccess='always'" to your embedding tag.

  6. #6
    Junior Member
    Join Date
    Sep 2008
    Posts
    6

    Smile thank you 5TonsOfFlax!

    You have cracked it!

    Have a beer on me

    Many many thanks!

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