A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Actionscript Developer KigD's Avatar
    Join Date
    Jan 2003
    Location
    georgia
    Posts
    597

    Converting a string to a variable

    I have a problem,
    I'm making this message cycling headline popup thingy.
    This is my code for one of the frames:

    Let's say that i declared a variable "headline1 = "Hello Everybody!"
    on one frame. I have a counter called "hnews" as well that starts at 0 and goes to a limit.

    the next frame i have

    PHP Code:
    var "headline"+_root.hnews
    scroller
    .thenews x
    I want the scroller to be equal to the variable headline1, not the string headline1. I've tried hundreds of things like brackets and curly braces, but all in vain.

    Plz help,
    Danny
    K2xL - My games, tutorials, message boards, and experiments.
    Blog

  2. #2
    immoralator
    Join Date
    Dec 2001
    Location
    UK
    Posts
    270
    Try
    code:
    var x = eval("headline" + _root.hnews);


  3. #3
    Actionscript Developer KigD's Avatar
    Join Date
    Jan 2003
    Location
    georgia
    Posts
    597
    Sweet, thanks,
    but i have another question now...
    I tried making an array and a for loop to load variables from a txt file.
    PHP Code:
    loadText = new loadVars();
    loadText.load("Variables.php");
    loadText.onLoad = function(success) {
        if (
    success) {
            
    headlinecount this.headlinecount//total number of headlines
            
    headline = new Array(headlinecount);
            for (
    a=0a<headlinecounta++) {
                
    headline[a] = this.headline[a]); // < - here is problem
            

    In my file,
    i have

    &headline1=Yo
    &headline2=Yo
    &headline3=Yo
    &headline4=Yo

    So headlinecount should be 4.



    It don't work. How can I get the index of the array?


    Thanks!
    K2xL - My games, tutorials, message boards, and experiments.
    Blog

  4. #4
    Junior Member
    Join Date
    Sep 2003
    Location
    The Hague, The Netherlands
    Posts
    2
    In your file, did you use ' and ; ?
    &headline1 = 'Yo';
    &headline2 ..... etc.

  5. #5
    Actionscript Developer KigD's Avatar
    Join Date
    Jan 2003
    Location
    georgia
    Posts
    597
    No, and i don't think i need to...
    K2xL - My games, tutorials, message boards, and experiments.
    Blog

  6. #6
    immoralator
    Join Date
    Dec 2001
    Location
    UK
    Posts
    270
    Use a for in loop to pull out all the data from the textfield then you won't need to know how many exists in the file. If you need to use the value later, increment a counter in the for in loop and reference to that.

    I'd personally use XML for this, then you can use childNodes.length to specify the for loop's properties, but I like whoring XML everywhere I go. It's worth looking up though to replace usage of textfiles...

  7. #7
    Actionscript Developer KigD's Avatar
    Join Date
    Jan 2003
    Location
    georgia
    Posts
    597
    Yeah, the for loop though has a constraint, see the file says how many variables the for loop should extract.
    K2xL - My games, tutorials, message boards, and experiments.
    Blog

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