This may be a simple request but I am just starting to wrap my head around the whole class idea.
I am attempting to create a simple class that will allow me to load dynamic content into a series of movie-clips, all generated based on an XML file. I want to be sure I am moving down the right path here so I thought I would ask.
So at present I have an XML file which I parse and then loop through to create new instances of a class I am calling speaker. I have a movie-clip in my library that I have associated with an .as file. I loop through the XML list, all of the clips get loaded onto the stage properly.
What I am attempting to do is adjust the content of those clips (load images, adjust dynamic text fields) Should I be writing those functions into the .as file? In my mind it seems like the most efficient way to do all of this would be to pass the new clip an XML node and the content gets populated based on functions that accept XML data inside the class. Honestly though, I would be happy if I could get a simple trace function to work from it. Here is what I am working with:
speaker_class.as
package {
import flash.display.;
import flash.events.;
public class speaker extends MovieClip {
public function speaker() {
this.addEventListener(Event.ADDED_TO_STAGE, trace_content, false, 0, true);
}
function trace_content(e:Event):void{
this.removeEventListener(Event.ADDED_TO_STAGE, trace_content);
trace("speaker loaded");
//load_images
//adjust dynamic text
}
}
}
timeline actions
function parse_xml(xml_data:XML):void {
var speaker_list:XMLList = xml_data.speaker.speaker_image;
for (var i:int = 0; i < speaker_list.length(); i++){
var rows:int = 3;
var speaker_clip:XML = speaker_list*;
var new_speaker:speaker = new speaker();
new_speaker.x = ((new_speaker.width+50) * int(i / rows))+25;
new_speaker.y = ((new_speaker.height+15) * (i % rows)) + 25;
new_speaker.name = speaker_clip;
addChild(new_speaker);
}
}