SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replacement for eval()

    I'm creating a AIR app and need to arrive at the dot notation path of: air.File.userDirectory.resolvePath

    in my function I'm passing in a where param
    var where = 'userDirectory';

    var f = eval('air.File.'+where+'.resolvePath')(file);
    eval would normally work, but in AIR eval is not allowed.

    Any other suggestions?

    -s

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Hurrah for AIR! Eval is evil.

    YOu can use an array-index notation instead.

    Code javascript:
    var f = air.File[where].resolvePath(file);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant!
    I had tried
    Code:
    var f = alr.File.[where].resolvePath(file);
    but found errors.

    Thanks for the tip

    -s

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Oh yeah, there's an obvious mis-spelling there. alr should be air
    Updated now.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jQuery.air.js plugin almost ready

    -s

  6. #6
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    pmw's tip also applies to any EMCA (sp?) language like Actionscript, which I'm guessing you use at least occasionally if you're working with Adobe Air.

  7. #7
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great thanks.
    Its been a couple of years since I have coded any actionscript, but still occasionally find myself casting ie. var myString:String = 'bla bla';
    as and js are first cousins and their compilers are the same.

    -s

  8. #8
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by suprsidr View Post
    Great thanks.
    Its been a couple of years since I have coded any actionscript, but still occasionally find myself casting ie. var myString:String = 'bla bla';
    as and js are first cousins and their compilers are the same.

    -s
    Strictly speaking, actionscript is compiled and javascript is interpreted. While actionscript has eval(), it is not a full code interpreter and cannot be used to evaluate arbitrary expressions. The reason for this lies within the fact that compiled languages (even partially compiled bytecode languages like actionscript or java) do not have a compiler present at runtime.


Tags for this Thread

Bookmarks

Posting Permissions

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