A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Help with Arrays

Hybrid View

  1. #1
    That web bloke Stoke Laurie's Avatar
    Join Date
    Jan 2006
    Location
    England
    Posts
    869

    Help with Arrays

    MyArray=new Array('Mary,Had a lamb','Humpty,He fell down')
    is typical of how an array would look (for example in Brett's namesearch example)
    Could someone help me with the correct syntax if you want to replace the values in an array with variables so that by using
    var name1 =txt1var
    I can include name1 in the array and have it changed dynamically.
    I realise that for each item in the array I will have to set up a separate variable.
    Thanks in anticipation guys.

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    If I understand you correctly you want to have a textbox dynamically show the value of an array element.

    I'm sure you could by setting a function to update the textboxes and set it going with setInterval. I can't remember how to write the part where you refer to a named item like txt1 txt2 etc within a loop (I know you can)

  3. #3

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Using a three item array example....we'll twist it at runtime and change the value of item 1. This example pushes a hard coded text string into it but wouldn't matter if I pushed it from an input textfield...it's the same deal.

    Make an empty movie. Make a dynamic textfield (about 400 pixels wide) with an instance name of "txt1" (the default). Then place a button component onstage (it should default to an instance name of "pushbutton1".

    Paste this on frame 1 and run it.

    var MyArray=new Array('Stoke had a valid question','He hoped to get some attention','He waited and waited and found');
    this.onEnterFrame=function(){
    txt1.text=MyArray[0];
    }
    pushbutton1.onPress=function(){
    _root.MyArray[0]="Not Getting An Answer Sucks";
    }


    Now...next time you have a question like this...might I suggest the "Scripting and Backend" forum or "Flash Actionscript" forum so as not to be left hanging. This was not specific to Koolmoves and you'll get better response.

  5. #5
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205

    that's where I got lost

    Quote Originally Posted by Chris_Seahorn

    Then place a button component onstage (it should default to an instance name of "pushbutton1".

    Paste this on frame 1 and run it.
    I was following along nicely until this point. I hit f11 and selected the button component, but it did not default to that name. I pasted the code on frame 1 of the main movie (later thought maybe Chris means frame one of the button?) and ran it and saw a text. Is this all that should happen or should the text change with the button somehow? How to make it change?

    BTW--what is the diff between Shapes/Add Button and View Symbols/Components/KC8 Add Button?

    This array stuff looks so useful.

  6. #6

  7. #7

  8. #8
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Now...next time you have a question like this...might I suggest the "Scripting and Backend" forum or "Flash Actionscript" forum so as not to be left hanging. This was not specific to Koolmoves and you'll get better response.
    Ouch, sorry I didn't have time to research it just then.....

    Only got 2 hours of sleep but here you go.

    Anyway I worked it out for you Stoke
    code:

    myArray=new Array("one","two","three","four");


    function update(xa){
    var x,y
    for (x=0;x<xa.length;x++){
    y=x+1
    _root['txt'+y.toString()].text=xa[x];
    }
    updateAfterEvent()
    }

    setInterval(update,50,myArray);
    stop()



    Note that so that you don't have to hand code for every array element I've used:
    _root['txt'+y.toString()].text=xa[x];
    This lets you refer to a all textboxes in a loop the reason I had to use another variable is that the textboxes default to starting with 1 and an array starts at 0

    Also using setInterval is only way if you want to be able to keep doing in the scope of the _root timeline and not in a child movieclip.

    I've attached an example that shows this function working
    Attached Files Attached Files

  9. #9

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