Hello All,
As my exams are nearly over (just 2 weeks ^^ ) I decided as a break between revision I would look back to AS3 and OOP and once again I have Confused myself =[
All I Want To Do Is:
Access a variable from another class. To my very inexperienced mind this sounds simple…
Here is my example classes.
ActionScript Code:
[LEFT][COLOR=#808080]*//Document Class*[/COLOR]
package [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]import[/COLOR] flash.[COLOR=#000080]display[/COLOR].*;
[COLOR=#0000FF]import[/COLOR] com.[COLOR=#0000FF]xml[/COLOR].[COLOR=#000080]xmlLoad[/COLOR];
[COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**class**[/COLOR] main [COLOR=#0000FF]extends[/COLOR] [COLOR=#0000FF]MovieClip[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**var**[/COLOR] _targetURL = [COLOR=#FF0000]"Musicinfo.xml"[/COLOR];[COLOR=#808080]*//This is the var that i want to share*[/COLOR]
[COLOR=#000000]**var**[/COLOR] getXML:xmlLoad = [COLOR=#000000]**new**[/COLOR] xmlLoad[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**function**[/COLOR] main[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]*// Do stuff with the xml here*[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]//xml Loader class[/COLOR]
package com.[COLOR=#0000FF]xml[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]import[/COLOR] flash.[COLOR=#000080]events[/COLOR].;
[COLOR=#0000FF]import[/COLOR] flash.[COLOR=#000080]net[/COLOR].;
[COLOR=#0000FF]import[/COLOR] flash.[COLOR=#0000FF]xml[/COLOR].*;
[COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**class**[/COLOR] xmlLoad [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**function**[/COLOR] xmlLoad[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#000000]**var**[/COLOR] fileURL = _targetURL[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#808080]*//This is the var from the Document Class*[/COLOR]
[COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR]fileURL[COLOR=#000000])[/COLOR];
[COLOR=#000000]**var**[/COLOR] xmlFile:URLRequest = [COLOR=#000000]**new**[/COLOR] URLRequest[COLOR=#000000]([/COLOR]fileURL[COLOR=#000000])[/COLOR];
[COLOR=#000000]**var**[/COLOR] _loader:URLLoader = [COLOR=#000000]**new**[/COLOR] URLLoader[COLOR=#000000]([/COLOR]xmlFile[COLOR=#000000])[/COLOR];
_loader.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]Event.[COLOR=#000080]COMPLETE[/COLOR], makeXML, [COLOR=#000000]**false**[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000000]**true**[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]**function**[/COLOR] makeXML[COLOR=#000000]([/COLOR]evt:Event[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR]evt.[COLOR=#0000FF]target[/COLOR].[COLOR=#0000FF]data[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]
Now I do think that i could make that variable in the xmlLoad class but I just simply want to know if sharing vars like that could be done and a working example would go down very nicely too xD
I though useing a get function would work but it didn’t
Thanks if you can help me understand this