Advertisement

05.13.2008 at 03:31AM PDT, ID: 23397195
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Accessing array variables (from XML)  from within  a nested function

Tags: ActionScript
I'm having real trouble accesing a variable that is coming from an XML file, please see attached function:

basically trace(linkname[i].attributes.prjName); comes back as undefined. If I place it outside the onRollOver function (like just before it) it works great but inside the function it wont.

Anyone?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
populateList = function () {
	propertyList.removeAll();
	var propertyXML:XML = new XML();
	propertyXML.ignoreWhite = true;
	propertyXML.load(_global.whichXML);
	propertyXML.onLoad = function() {
		var linkname:Array = this.firstChild.childNodes;
		for (i=0; i<linkname.length; i++) {
			mainMap.mapCont.develpment.onRollOver = function() {
				trace(linkname[i].attributes.prjName);
			};
		}
	};
};
populateList();
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: kalisan
Solution Provided By: Vulturous
Participating Experts: 2
Solution Grade: A
Views: 9
Translate:
Loading Advertisement...
05.13.2008 at 04:24PM PDT, ID: 21560133

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.13.2008 at 04:29PM PDT, ID: 21560163

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.13.2008 at 09:28PM PDT, ID: 21561266

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 05:47AM PDT, ID: 21563484

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 07:05AM PDT, ID: 21564329

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 07:45AM PDT, ID: 21564769

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 09:01AM PDT, ID: 21565596

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 09:04AM PDT, ID: 21565632

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 07:15PM PDT, ID: 21570175

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.14.2008 at 09:50PM PDT, ID: 21570724

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.13.2008 at 04:24PM PDT, ID: 21560133

Rank: Guru

Yeah, it will come as undefined, since Flash doesn't know which element you're using...

The onRollOver function should be outside that for since that for is just parsing the data, and it's overwriting the rollOver function everytime it finds a new item, and in the end, "i" doesn't say anything to the function if it's used after the for has finished....

It would also be good to know what are you trying to do - as in, why do you need a rollOver on the same button displaying different data.

-V
 
05.13.2008 at 04:29PM PDT, ID: 21560163

Rank: Guru

hi,

i wrote an xml parser that parses your xml into a flash object for easy referencing.  this might make your life easier.

take the following xml:

<root>
    <main>
        <link>first link</link>
        <link>second link</link>
    </main>
</root>

this will be parsed into:

var xmlobject:Object = XMLParser.parse(xml);
trace(xmlobject.root.main.link[1]); // outputs "second link"
 
remove the .txt
 
 
05.13.2008 at 09:28PM PDT, ID: 21561266
Good point, i'll expllain it. Its for an interactive map. there are areas on the map which each exist as movieclips. When you rollover the area a bubble comes up telling you what it is and if you click on it it will link to more info.

I am able to target the individual areas (mainMap.mapCont[linkname[i].attributes.prjRef]) but I cant tell them what to do on roll over or on click. I was showing a simplified code snippet before but now i've pasted it as I have it. Basically i'm trying to set the roll over states for the 50 odd areas on the map. prjRef which is coming from the XML is the same as the name of the movie clip on the map that it is supposed to target. All the clips is the map have been pre-named so i'm just trying to asign what they should all do. Their proper names and linsk etc is also coming from the XML file.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
populateList = function () {
        propertyList.removeAll();
        var propertyXML:XML = new XML();
        propertyXML.ignoreWhite = true;
        propertyXML.load(_global.whichXML);
        propertyXML.onLoad = function() {
                var linkname:Array = this.firstChild.childNodes;
                for (i=0; i<linkname.length; i++) {
                        mainMap.mapCont[linkname[i].attributes.prjRef].onRollOver = function() {
                                trace(linkname[i].attributes.prjName);
                        };
                }
        };
};
populateList();
Open in New Window
 
05.14.2008 at 05:47AM PDT, ID: 21563484
Vulturous, just to clarify. The first part is working great.t. All the map areas are being activated i.e. when you rollover them the cursor changes to a hand and trace = undefined comes up. So the 'for' loop is asigning the trace to each area. I just cant figure out how to parse the variables from within the onRollOver function.

Is this making sense?

tagit, i've tried to use your parser but to be honest not sure how to get it to work. Do you think it will solve my problem now that I have explained it better?
 
05.14.2008 at 07:05AM PDT, ID: 21564329
OK from Vulturous's initial raction I got the impression that you can not declare a function within a loop. Is this correct?
In order to get round this i've tried something else but this is also not working. See attached code. I've now calling the fuction which is external of the loop but it does not populate all the areas, only the last one in the list comes though :(
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
activateMap = function (prjName, prjRef) {
	mainMap.mapCont.prjName.onRollOver = function() {
		trace(prjRef);		
	};
};
 
 
populateList = function () {
	propertyList.removeAll();
	var propertyXML:XML = new XML();
	propertyXML.ignoreWhite = true;
	propertyXML.load(list.xml);
	propertyXML.onLoad = function() {
		var linkname:Array = this.firstChild.childNodes;
		for (i=0; i<linkname.length; i++) {
			prjName = (linkname[i].attributes.prjName);
			prjRef = (linkname[i].attributes.prjRef);
			activateMap(prjName,prjRef);
		}
	};
};
populateList();
Open in New Window
 
05.14.2008 at 07:45AM PDT, ID: 21564769

Rank: Guru

Oh, yes you can declare a function within a loop - on your "simplified" version you made reference to the same MovieClip, thus making it useless for the others. But yes, you can... something like this may be helpful though:

<code>

-V
1:
2:
3:
4:
5:
6:
7:
                for (i=0; i<linkname.length; i++) {
                        currentMovie = mainMap.mapCont[linkname[i].attributes.prjRef];                                                
                        currentMovie.myName = linkname[i].attributes.prjName;
                        currentMovie.onRollOver = function() {
                                trace(this.myName);
                        };
                }
Open in New Window
Accepted Solution
 
05.14.2008 at 09:01AM PDT, ID: 21565596
You're an absolute legend, thank you very much, worked like a charm :-)
 
05.14.2008 at 09:04AM PDT, ID: 21565632
I just wish I understood exactly why it works  ;-)
 
05.14.2008 at 07:15PM PDT, ID: 21570175

Rank: Guru

I'm glad you got it working. And thanks a lot, 'cause in the end this is our payment :)... these kind of comments are what make us proud of helping you guys out :).

Now... why it works:

The secret is here:

currentMovie = mainMap.mapCont[linkname[i].attributes.prjRef];                                                

// Here I just save the current iteration (since we're on a for) to a temporal variable (currentMovie) to use it later... BUT that instance name already exists, I'm just using a reference to it :)

currentMovie.myName = linkname[i].attributes.prjName;

// Since MovieClips are so flexible I decide to add some random property (myName) to save whatever information I want and use later (remember that this variable already existed, I'm only adding data to it)

currentMovie.onRollOver = function() {

// Just applying an action to my saved instance

    trace(this.myName);

// And here I just call the variable I added, since I made it for every MovieClip, it shows me it's own specific data. :)
};

Why didn't trace(mainMap.mapCont[linkname[i].attributes.prjRef]); work?

You're on an iteration, the data flows and fills whatever you ask it to do but it doesn't "stay" there, it just does it process then goes back to what it originally was ("i" was undefined outside of the scope of the for). So, since the for gets executed and then finishes, "i" stands for nothing and I'll always get undefined 'cause the value is lost, that's why I need to save it in a variable, preferably making it a property of the object that I'll use later.

Hope this is clear enough... I think I typed too much...

-V
 
05.14.2008 at 09:50PM PDT, ID: 21570724
Thanks a lot for the explanation. Its begining to all make sense now :-)
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628