I began with a class for a movie clip rollover function FigureRollOver. It
works marvellously. Three things happen:
1) it loads XML from a file "mod1_fig1.xml" and uses another class, XMLMember,
to retool the scoping of the XML so that I can get at it
2) an onload call inside of XMLMember calls the myOnLoad function and
transfers the XML into an array.
3) so long as the array is finished building, rolling over a movie clip
attaches a new movie clip with the rollover text in it.
But I don't want all those functions in one because I need it to be more
dynamic, starting with being able to load any old xml file instead of just
"mod1_fig1.xml", plus it seems like overbuilding to have all of that in one
class, so I've separated out the loading of the XML and building of the array
into its own class, FigureXMLLoader. FigureRollOver is then left to just attach
the rollover with text in it, extracted from the array built by the new class.
Problem is, though the array builds inside FigureXMLLoader, I can't figure out
how to make it available outside the class. I know that I'm constructing things
in the wrong order, and that the array needs to be somehow built inside the
class function to be available, but I can't figure out how to do that. A cruddy
work-around is to put a function call at the end of the building of the array,
which calls yet ANOTHER function on the main timeline of my .swf to put the
array I've just built into a new variable. This works, but it's messy. It seems
like I should be able to have one line of script in the .swf that generates an
array on the main timeline (or just a public array) which I can then access
from my FigureRollOver class:
var myRollOvers:Array = new FigureXMLLoader("mod1_fig1.xml");
Here is FigureXMLLoader (see comments in the code for more details) which
obviously does not return an array as it is, because of all the working around
I've had to do. Note the "testing" variable, which can be traced from the main
timeline of the .swf, but I will get "not what I want" because of course the
array hasn't been built yet, and never will be, inside of the declaration as it
is. How do I get it in there so I can return an array?
Thanks!
class FigureXMLLoader {
private var content_xml:XML;
public var figure_arr:Array;
public var testing:String;
public function FigureXMLLoader(myURL:String) {
this.figure_arr = [];
this.testing = "not what I want";
content_xml = new XMLMember(this, "myOnLoad");
content_xml.ignoreWhite = true;
content_xml.load(myURL);
}
private function myOnLoad(xmlData:XML) {
var e = xmlData.firstChild;
if (e.nodeName == "FIGURE") {
e = e.firstChild;
while (e != null) {
var item:Object = new Object();
item.itemName = e.attributes.NAME;
item.pointerDir = e.attributes.POINTER;
item.blurb = e.firstChild.nodeValue;
figure_arr.push(item);
e = e.nextSibling;
}
//I could call a function here
testing = "this is what I want";
}
}
}
maija_g - 30 Aug 2006 18:32 GMT
Update: I've now put this on the main timeline of the .swf:
myRollOversLoaded = false;
var myRollOvers:Array;
var roll_content = new FigureXMLLoader("mod1_fig1.xml");
And inside the "myOnLoad" function in FigureXMLLoader, just after the while
loop I've put this:
_root.myRollOversLoaded = true;
_root.myRollOvers = figure_arr;
The movie clip rollover won't act until myRollOversLoaded is true. It works,
but it still seems klugey. Any suggestions for a more elegant solution would be
appreciated.
Motion Maker - 31 Aug 2006 11:50 GMT
Suggest you ask this question in the Actionscript forum as this forum is
more tuned to database integration questions.
You can create arrays outside a class and pass them into it by reference and
visa versa build arrays inside a class and pass out via reference.
The preferred approach is to place the array in a class and not expose it.
Then add methods to use the array or should we say to use the class.

Signature
Lon Hosford
www.lonhosford.com
Flash, Actionscript and Flash Media Server examples:
http://flashexamples.hosfordusa.com
May many happy bits flow your way!
> Update: I've now put this on the main timeline of the .swf:
>
[quoted text clipped - 14 lines]
> would be
> appreciated.