A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: newb question:What are Arrays?

  1. #1
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870

    newb question:What are Arrays?

    Quite Basic Questions I have, yet quite complicated answers I think I am gonna get from these newb questions.
    What are Arrays? and How do you use them? and How to use a specific number to point into a variable in a array group?..
    Regard,
    Tongxn

    p.s. Im just asking this coz i read this script about making an electric Clock in Flash...
    p.s.s. Its impossible to search Array, so don't try.
    Last edited by tongxn; 04-24-2006 at 03:11 PM.
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  2. #2

  3. #3
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Arrays are kinda like variables but much bigger. Meaning that they hold alot information in them and can then be used to display that info or store it. Heres a small example:

    code:
    var aEmployees:Array = new Array(4);
    aEmployees[0] = "Arun";
    aEmployees[1] = "Peter";//these are what you start out on in the array
    aEmployees[2] = "Chris";
    aEmployees[3] = "Heather";
    aEmployees.push("Billy");//this adds a new item to the bottom of the array
    aEmployees.unshift("Bobby");//this adds new item to the top of the array
    aEmployees.splice(2, 0, "Amy");//this adds to array, but anywhere
    trace (aEmployees.String);


  4. #4
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    oh so you set the array aEmployees and then you give something like a reference number to the thing..

    //right?
    aEmployees[0] = "Arun";
    // so if there's a variable like -
    description = aEmployees[0];
    // is that how you call it up?
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  5. #5
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    basically yes...then you have MULTI-DIMENSIONAL ARRAYS as well.. whre each element [x] in the parent/main array is an array itself..

    example:
    code:

    var productName:String = prodNumber[1].prodName[0];



    you'll like them..they are fun...

    the real power comes from being able to use them with LOOPS...

  6. #6
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Multi ah, haven't used them before. I'll have to experiment with it sometime. Do they work just a regular array, but instead hold another array?

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    exactly...just that each element in the MAIN array is also an arraywith its OWN elements..

    Main[1].sub[4]

    etc..etc..



    if you know how to path/run through arrays..you'd have NO problem using XML now...

  8. #8
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Ok, I gotcha. Doesn't sound to bad.

    I'm not too sure if I'm ready for XML. But thanks for the input Whispers.

  9. #9
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    I think you are..you'd be surprised how EASY it is..once you walk through one ot two examples...

    the only NEW thing you need to pick up is the XML commands.. (firstNode, childNode, parentNode..etc) all self explainitory...

    you treat it the same way you would a larVars object..except its an XML object...and once loaded..you treat it like an ARRAY (XML is really just one big array)

  10. #10
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    I see, thats kinda cool. I wouldn't mind learning XML and possible php. But don't you need server stuff to work with either of them, or am I looking into something else?

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    for PHP you need to have your scripts on a web server..whether your web host or a personal Apache/IIS install on your machine (comes on XP Pro disk I believe)

    XML you can test locally no problems...just like a .txt file. It bascially "IS" just a text file...except that theINSDIE contents..are parsed in as an ARRAY

  12. #12
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Oh okay, i see. Just from hearing the guys at work talk about XML, it always sounded like they were talking about server stuff. Must have misinterpeted what they were say'n.

    I'll have to find some tutorials on them now. At least XML.

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    XML itself it nothing.... EASY as pie... sorta like HTML...but you get the flexibility of making up your OWN tags names... it does NOTHING visually to you content.. its just a way of organizing it.

    example: I want to make an XML file to organize a book content/data.
    (and I make and use what I want)
    PHP Code:
    <book>
        <
    author>Joe Blow</author>
        <
    title>some book</title>
    </
    book
    thre ya go..an XML file... nothing to it.. the HARD part is what system is going to PARSE this XML file and "WHAT" to do with this data...

    FLASH has its own XML parser..and reads the XML file in as a BIG ARRAY object.
    book being the first array element.. you can access them as such: firstNode, childNode, siblingNode..etc.. or firstNode.ChildNode... that would be the author NODE.

  14. #14
    XRave tongxn's Avatar
    Join Date
    Apr 2005
    Location
    Somewhere near Here
    Posts
    870
    mm so how do you set up a path to a variable inside an Array?
    It sounds quite cool and makes AScripting easy but

    Is it like the type i used or what?

    Thanks for the Imput guys.
    When you actually know what "OMG I have so much homework!" means, you won't want to be me.
    Xrave

  15. #15
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    well if its XML..you would use the XML actions liek childNode and what not..but still similar.. (and theres only a few)

    example: (for a store/shopping cart I made)
    code:

    //create XML object
    myXML_xml.ignoreWhite = true;
    myXML_xml.onLoad = getTotalProducts;
    myXML_xml.load("products.xml"); //local version

    //what to do when/if the XML file loads
    function getTotalProducts(success):Void {
    if (success == true) {
    // make quick refernece VARIABLES to the certain NODES in my XML object (faster then typing them all out each time)
    rootNode = myXML_xml.firstChild;
    productsNode = rootNode.childNodes;
    totalProducts = rootNode.childNodes.length; //counts how many total "products/nodes" I have
    // a function that attaches as many CLIPS as there are child nodes in my XML document
    createTemplates();
    }else {
    trace("Load Failed");
    }
    }

    //function to attachClips according to the totalProducts
    function createTemplates():Void {
    for (i=0; i<totalProducts; i++) {
    var attachProduct:MovieClip = attachMovie("templateClip", "product"+i, i);
    attachProduct._y +=10;
    attachProduct._y += i * 50;
    }
    }


  16. #16
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Well, from your example up top your close. Instead of,
    description = aEmployees[0];

    You'd have it like this.
    code:
      var description:Array = new Array
    description[0] = "Arun"


    And if you want to refer to something in it you use desription and then whatever line it is in.

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