A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Urgent - array access

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Posts
    292

    Urgent - array access

    I can load the variables I need into an array with the following, BUT...outside of the success function, how can I access the array variables?


    code:
    var navVars = new LoadVars();
    navVars.load("variables1.txt");
    navVars.onLoad = function(success) {
    if (success) {
    //trace that the variables have loaded
    //trace("success")
    //trace the type of object you are dealing with
    //trace(typeof (this.level1)); // string
    //split the varibles into their respective arrays
    this.navArray1=this.level1.split(":");
    this.navArray2=this.level2.split(":");
    trace(typeof (this.navArray1));
    trace(this.navArray1.length); // 4
    trace(this.navArray1[0])

    array_length = this.navArray1.length;
    for (i=0; i<array_length; i++) {
    trace(this.navArray1[i]);
    }

    }
    };

    If you feel like your going through hell....just keep on walking

  2. #2
    Senior Member
    Join Date
    Jul 2002
    Posts
    292
    For anyone that is interested.

    I created a global array in the success function that allowed me to access it.

    I also realised that I could access it from navVars.navArray1

    If anyone know which is the better way to do it then please let me know
    If you feel like your going through hell....just keep on walking

  3. #3
    Re Member websam's Avatar
    Join Date
    Jul 2000
    Location
    Australia (VIC)
    Posts
    660
    There are pros and cons for both solutions and really depend on where you need to access the arrays.

    navVars.navArray1
    pros:
    minimize name space conflict where you can re-use navArray1 elsewhere
    cons:
    performance wise, you are creating more complex hierachy which reduces the performance (hardly detectable but counts)

    global
    pros:
    access directly from anywhere
    cons:
    too much global variables makes harder in code management

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