A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Reducing lines of Actionscript...

  1. #1
    Senior Member
    Join Date
    May 2001
    Location
    Holland
    Posts
    286

    Reducing lines of Actionscript...

    Hi,

    I need to load a very big xml-feed, that has lots of nodes in it. Now I've reached some limit in actionscript that prevents the code working correctly. I've already seperated lines of code outside the function that causes the problem and would your help to reduce the following typical handling o a node:

    Actionscript Code:
    if (Fruit_shape_EN_array[this.id].length>0 && _root.taal == "eng") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_EN_array[this.id];
                        }
                        if (Fruit_shape_NL_array[this.id].length>0 && _root.taal == "nl") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_NL_array[this.id];
                        }
                        if (Fruit_shape_IT_array[this.id].length>0 && _root.taal == "it") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_IT_array[this.id];
                        }
                        if (Fruit_shape_SP_array[this.id].length>0 && _root.taal == "sp") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_SP_array[this.id];
                        }
                        if (Fruit_shape_GE_array[this.id].length>0 && _root.taal == "ge") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_GE_array[this.id];
                        }
                        if (Fruit_shape_PL_array[this.id].length>0 && _root.taal == "pl") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_PL_array[this.id];
                        }
                        if (Fruit_shape_RU_array[this.id].length>0 && _root.taal == "ru") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_RU_array[this.id];
                        }
                        if (Fruit_shape_FR_array[this.id].length>0 && _root.taal == "fr") {
                            variety_details += "\n\n<b>Fruit shape:</b>\n"+Fruit_shape_FR_array[this.id];
                        }

    "Fruit_shape_EN" for example is a node containing Engelish text, the other seven nodes are different languages. Besides "fruit_shape" there are about 60 other nodes with 8 language versions, and I have to determine which one to add to the "variety_details"-variable bases on which language-version the website needs to show ("_root.taal")... unfortunately, it's not possible to load the data directly from MySQL... so my question is: do you know a way to write the above code in a shortened way?

    Many thanx for your help!

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    can you load all XML data into an array or object array..

    decide the language setting... and then use ONLY that specific NODE/LANGUAGE order?

    example..


    if LANG == ENG

    then you know ALL ENG nodes are element[0] so no more checking on each now..just one parent level check to set the childNode for each 'element'?

    Im curious as to what FLASH limits you are running into though?





    actionscript Code:
    var langChoice = _root.taal;
    var tragetNode:Number;

    switch (langChoice) {
     case "eng" :
     trace("english");
     tragetNode = 0;
     break;
     case 'fr' :
     trace("french");
     tragetNode = 1;
     break;
     case "it" :
     trace("italian");
     tragetNode = 2;
     case "sp" :
     trace("spanish");
     tragetNode = 3;
     default :
     trace("unknown language");
    }

  3. #3
    Senior Member
    Join Date
    May 2001
    Location
    Holland
    Posts
    286
    Hi Whispers,

    Thank you for your reply. Your solution might be the most efficient but I resolved it by breaking the biggest part of the code into 3 major functions (create about 200 arrays, push the arrays, and read specific arrays based on the language setting).

    I try to explain the limit I encountered:
    - I load the big xml-file and within an myXML.onLoad-function and created a lot of arrays, read the nodes and pushed the data into the arrays;
    - I instantiated mc's which, after onRelease(), populates a variable (variety_details)based on the language (and if there's any data at all in a node, but that besides)
    - Now, the code in my first post was within that onRelease() and at some point (I can't tell you right now exactly after how many lines of code), it just didn't work anymore. No error or crash, the function stopped executing at some point.
    - I'm not sure if it's a limit in the number of lines an onRelease()-function can have, or that there's a limit in a myXML.onLoad-function...

    I (still) use Flash 8.

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    I use CS3.. (and I used F8 pretty heavily!..)

    I would tend to believe more of a corruption than a line/code limit...

    anyways your approach of making functions to perform certain tasks is a better approach. (more oop)

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