create a dynamic variable

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default create a dynamic variable

    Hi !

    i would like to know how to create a dynamic variable with flash.

    I'm getting 2 strings from XML and would like to create a variable named with the first string and with the value of the second string ... something like this :

    _root.myFirstString = mySecondString;

    how can i do this?

    Thanks a lot for your help!




    TeknoPhil
    [email]teknophil@__NO_SPAM__hotmail.com[/email]
    TeknoPhil webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. Dynamic Where variable
      I'm attempting to create a complete "Where" statement and save it to a variable. It works fine when comparing a numeric field against a number but...
    2. Create Variable
      Hi, I wanted to ask, how can I for Simple Connection component, username text field, set a variable? Thanks Lanex:beer;
    3. Create custom CGI. variable
      Does anyone know how I could create a variable that would appear in the #cgi# scope ? I have x number of coldfusion servers and on each one of...
    4. Dynamic Variable ... how can I ?
      Hi ! I need to disabled some buttons. Here's some AWEFUL code I have : for (i=1996; i<=2004; i++) { if (_root.year_array == false) { if...
    5. create variable before redirection.
      I'm trying to set a variable before redirection. Here is the code: //header("Location: /ManageProfile.php?UserID=".$id); echo("<input...
  3. #2

    Default Re: create a dynamic variable

    str1 = "vari";
    str2 = "ables";
    this[str1] = str2;
    trace(this[str1]);

    /* Ctrl+Alt+V to List Variables (MX)
    Variable _level0.str1a = "vari"
    Variable _level0.str2a = "ables"
    Variable _level0.vari = "ables"
    */

    regards
    Jack..
    Jack. webforumsuser@macromedia.com Guest

  4. #3

    Default Re: create a dynamic variable

    Thanks for this VERY quick response Jack!


    TeknoPhil
    [email]teknophil@__NO_SPAM__hotmail.com[/email]
    TeknoPhil webforumsuser@macromedia.com Guest

  5. #4

    Default Re: create a dynamic variable

    something else ;)

    if i want to add a string to my variable name ... ?

    example :
    string1 = "joe"
    string2 = "blow"

    like add a "a" so my variable name is "ajoe"

    thanks a lot

    TeknoPhil
    [email]teknophil@__NO_SPAM__hotmail.com[/email]
    TeknoPhil webforumsuser@macromedia.com Guest

  6. #5

    Default Re: create a dynamic variable

    str1 = "vari";
    str2 = "ables";
    this["a"+str1] = str2;

    /*
    Variable _level0.str1 = "vari"
    Variable _level0.str2 = "ables"
    Variable _level0.avari = "ables"
    */


    regards
    Jack..
    Jack. webforumsuser@macromedia.com Guest

  7. #6

    Default Re: create a dynamic variable

    actually i would likw to get something like this :
    str1 = "vari";
    str2 = "ables";

    so

    a_vari = ables


    i tried your solution :
    this["a_"+str1] = str2;

    but it's still give me this :

    vari = ables


    thanks

    TeknoPhil
    [email]teknophil@__NO_SPAM__hotmail.com[/email]
    TeknoPhil webforumsuser@macromedia.com Guest

  8. #7

    Default Re: create a dynamic variable

    how are you checking your returned variable ?

    i have this code -

    str1 = "vari";
    str2 = "ables";
    this["a_"+str1] = str2;

    on the main timeline i have a dynamic text field
    it has a variable name of - a_vari,

    the textfield displays "ables" and listing the variables returns -

    Variable _level0.str1 = "vari"
    Variable _level0.str2 = "ables"
    Variable _level0.a_vari = "ables"

    Edit Text: Target="_level0.instance1"
    variable = "a_vari",
    text = "ables",


    regards
    Jack..
    Jack. webforumsuser@macromedia.com Guest

  9. #8

    Default Re: create a dynamic variable

    I'm using this in a function ... if i trace right after my declaration, everything is fine.

    But my problem is that this movie is loaded from another one ... and I want to be able to play this movie alone OR from another movie (loaded in a movie clip) so I was wondering if I can declare the dynamic variable directly on _root ...

    Thanks a lot for you help!



    TeknoPhil
    [email]teknophil@__NO_SPAM__hotmail.com[/email]
    TeknoPhil webforumsuser@macromedia.com Guest

  10. #9

    Default Re: create a dynamic variable

    in sub.swf -
    str1 = "vari";
    str2 = "ables";
    this["a_"+str1] = str2;

    /* run alone would output
    Variable _level0.str1 = "vari"
    Variable _level0.str2 = "ables"
    Variable _level0.a_vari = "ables"
    */

    if loading sub.swf into a movieclip instance - loader that resides in the main movie,
    loader.loadMovie("sub.swf");
    /* this is the expected result
    Movie Clip: Target="_level0.loader"
    Variable _level0.loader.str1 = "vari"
    Variable _level0.loader.str2 = "ables"
    Variable _level0.loader.a_vari = "ables"
    */

    if you load to a level,
    loadMovieNum("sub.swf",1);
    /* the variable in sub.swf remains on its own level
    Level #0:
    Variable _level0.$version
    Level #1:
    Variable _level1.$version
    Variable _level1.str1 = "vari"
    Variable _level1.str2 = "ables"
    Variable _level1.a_vari = "ables"
    */

    i suggest you make more use of List Variables, (Ctrl+Alt+V shortcut)
    most of the answers to all kinds of problem hide there :)

    regards
    Jack..
    Jack. webforumsuser@macromedia.com Guest

  11. #10

    Default Re: create a dynamic variable

    Is the opposite also possible. If not, how would I do it?

    example:
    var = this["string"+var2+"string"];

    Essentially, I need to set var to the value of a second variable. The name of
    the second variable will change depending on other factors, and is being
    accessed via a while loop.

    totalLoops=5;
    i=1;
    while (i <= totalLoops){
    ItemType = this["_root.Item"+i+"Type"];
    if (ThisNum==count){
    if (_root.ItemType=="Options2"){
    gotoAndStop ("item");
    }else if (_root.ItemType=="false"){
    gotoAndStop ("false");
    }else if (_root.ItemType=="drink"){
    gotoAndStop ("drink");
    }else {
    Menu1.ItemName = _root.ItemName1;
    Menu1.ItemDescription = _root.ItemDescription1;
    Menu1.ItemPrice14 = _root.ItemPrice14One;
    Menu1.ItemPrice16 = _root.ItemPrice16One;
    Menu1.ItemPrice18 = _root.ItemPrice18One;
    }
    }
    i++;
    }

    Vayapues Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139