Welcome to TalkGraphics.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2000
    Location
    Dallas, Tx
    Posts
    277

    Default

    How can I use the value of a variable to perform and action?

    Example:
    I set variable "Code" to "_root.gotoAndPlay(2);"

    Code = _root.gotoAndPlay(2); //In root movie

    I want a movie clip to use this value and the end of it's timeline. The reason I need to use the entire string is because it might not always be a gotoAndPlay action. It might be a loadMovie or something else. How can I call on this value to use it as an action later? I've been successful at using variables to insert values into actions, but can't figure out how to use the values as the full actions.

    Thanks in advance,

    Scott
    IP

  2. #2
    Join Date
    Aug 2000
    Location
    Dallas, Tx
    Posts
    277

    Default

    How can I use the value of a variable to perform and action?

    Example:
    I set variable "Code" to "_root.gotoAndPlay(2);"

    Code = _root.gotoAndPlay(2); //In root movie

    I want a movie clip to use this value and the end of it's timeline. The reason I need to use the entire string is because it might not always be a gotoAndPlay action. It might be a loadMovie or something else. How can I call on this value to use it as an action later? I've been successful at using variables to insert values into actions, but can't figure out how to use the values as the full actions.

    Thanks in advance,

    Scott
    IP

  3. #3
    Join Date
    May 2001
    Location
    Dallas, TX and Essex, UK
    Posts
    38

    Default

    Depending on the version of Flash that you're using, you could go about this in a couple of ways.

    I tested this first approach in Flash MX, and it ought to work in Flash 5 too:

    Create a placeholder function which is what you will use to issue the command:

    function Code()
    {
    }

    Then create new functions that will do the various different things that you want to get done:

    function optionOne()
    {
    _root.GotoAndPlay(2);
    }

    function optionTwo()
    {
    LoadMovie...
    }

    When you want to change "Mode", you can set the Code funtion equal to the option that you require:

    Code = optionOne;
    or
    Code = optionTwo;

    To execute the option, you simply call the Code function:

    Code();

    Another approach, for earlier Flash versions, might be to have a seperate movie clip with your various code options on different frames:

    Frame 1
    _root.GotoAndPlay(2)
    stop

    Frame 2
    _root.LoadMovie...
    stop

    You can store your option number in a variable in _root:
    _root.CurrentOption = 1

    When you want to run the code, you can use GotoAndPlay:

    CodeMovieClip.GotoAndPlay(_root.CurrentOption)

    These should give some avenues to try out, let me know if anything needs more clarification.

    All the best.
    IP

 

 

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
  •