A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] [F8] Eval() Question

  1. #1
    </hate> dtone314's Avatar
    Join Date
    Jun 2005
    Location
    CA
    Posts
    262

    resolved [RESOLVED] [F8] Eval() Question

    This should be easy, and may be a stupid question, but bear with me, it's been a long day.

    I need to use the eval statement to execute my function properly. My problem is, the statement is correctly evaluated, but I need to execute what it evaluates. Check out my code below.
    Code:
    changeWallColor = function(newColor){
         eval("_root.previewWindow.walls."+newColor+".gotoAndPlay(1);")
    /////THE ABOVE NEEDS TO EXECUTE, BUT IS ONLY EVALUATED///////
    }
    Does that make sense? Currently nothing happens when this function is called, but I need it to make a certain MC play, based on what value is passed into this function. Thanks in advance!
    -dtøne-
    Flash CS4 | AS2
    Life is a journey, not a destination.

  2. #2
    </hate> dtone314's Avatar
    Join Date
    Jun 2005
    Location
    CA
    Posts
    262
    I'm retarded.

    eval("_root.previewWindow.walls."+newColor).gotoAn dPlay(1);

    Thanks anyway.
    -dtøne-
    Flash CS4 | AS2
    Life is a journey, not a destination.

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    use array notation instead of eval:

    PHP Code:
    function changeWallColor (newColor){
         
    _root["previewWindow"]["walls"+newColor].gotoAndPlay(1);

    P.S its better to write functions as

    PHP Code:
    function a(){


    rather than

    PHP Code:
    = function(){


    Last edited by silentweed; 11-07-2007 at 08:09 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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