Solved

*Need Muso's Help with this one*

Posted on 2004-10-02
6
146 Views
Last Modified: 2010-04-03
when I trace:

departmentArray.department[0].service.name
departmentArray.department[0].service[0].component.name
departmentArray.department[0].service[0].component[0].values.name

I get:

math
student_checkin
menu


shouldnt it be more like this?

departmentArray.department[0].name
departmentArray.department[0].service[0].name
departmentArray.department[0].service[0].component[0].name


Easy fix?
0
Comment
Question by:gmailrules
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:muso120999
ID: 12210783
Are you talking about this line, and that you think it should trace a value?

departmentArray.department[0].service[0].component[0].name

The thing is, I deliberately made the routine flexible, so that if you have different XML categories, you can simply change:

_root.categoryArray = new Array("department", "service", "component","values");

and you have a similar structure (to any depth required) for that too.

"values" is a holder (like "department"), and although there aren't multiple entries, it leaves the capability there to do so.

Do you honestly see this as a problem!?
0
 
LVL 1

Author Comment

by:gmailrules
ID: 12210828
Well it works great no doubt.  I just saw it as a lil confusing.  The reason why I wanted to rename the variables in the first place was to make it easier to understand.  It works , and that's whats most important so it's really not a big deal.  But this is what I'm talking about:

departmentArray.department[0].service.name  //I would think this variable would contain the value "student_checkin" since its the first sevice.  but instead its value is the department name.
                                                                    //The variable has "service.name" in it so it just seems to reason that that is what it would return.  
                                                                    //wouldn't something like "departmentArray.department[0].name" be a better choice to hold the department name?


I wasn't sure if this was something really simple to change so that's why I'm asking.  If you don't see the point in changing it then oh well.  It works anyways :D

Thanks a lot,

John
0
 
LVL 10

Expert Comment

by:muso120999
ID: 12210876
Actually I've been thinking again, and I know now that I can make the change you request without much of a problem, whilst keeping it flexible.

I'm off out for the day now, but I'll post a solution up later for you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:gmailrules
ID: 12210889
ok, great.  thank you :)
0
 
LVL 10

Accepted Solution

by:
muso120999 earned 500 total points
ID: 12212741
Right, sorry - my code was actually wrong as it was assigning values to the level below, when only length needs to do that...

function convertContent(obj:Object, level:Number) {
      var prop:String;
      var targetObj = new Object;
      var len:Number = 0;
      for (prop in obj) {
            if (typeof (obj[prop]) == "object") {
                  if (targetObj[_root.categoryArray[level]] == undefined) {
                        targetObj[_root.categoryArray[level]] = new Object();
                  }
                  targetObj[_root.categoryArray[level]].len = ++len;
                  targetObj[_root.categoryArray[level]][prop] = convertContent(obj[prop], level+1);
            } else {
                  targetObj[prop] = obj[prop];
            }
      }
            return targetObj;
}
//DO STUFF!!!
function result(tXML:Array) {
      _root.departmentArray = new Object();
      _root.categoryArray = new Array("department", "service", "component");
      _root.departmentArray = convertContent(tXML, 0);
        delete _root.categoryArray; // this is no longer required

      trace(departmentArray.department[1].service.len);
      for (prop in departmentArray.department[0].service[0].category[0]) {
            trace(prop);
      }
}

You will notice now that the arbitrary "values" should not be needed now (I did wonder this when I wrote it, but didn't spend the time I should have done analysing it!
0
 
LVL 1

Author Comment

by:gmailrules
ID: 12212926
Exactly what I wanted.  Thanks a lot Muso!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
3D rotation for a product 3 336
IE 11 Flash Player issue 7 232
Where to download Adobe Flash Player 11.9.900.170 5 1,326
blocked plugin flash 5 111
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now