I’m working on my first class – a class with extends the MovieClip class – and I would like to get some critiquing on the structure.
The class will be assigned to a library movieclip and attached/initialized on demand. This class is one of 2-3 that I’m building for different types of quiz questions.
////////////////////////////////////////////////////////////////////////////////
// IMPORT CLASSES
////////////////////////////////////////////////////////////////////////////////
import mx.utils.Delegate;
import mx.xpath.XPathAPI;
class MultipleChoice extends MovieClip
{
////////////////////////////////////////////////////////////////////////////////
// VARIABLE DECLARATIONS
////////////////////////////////////////////////////////////////////////////////
// private vars
private var itemsURL:String = "http://somewebsite.com/quiz/load_items_for_question.php";
private var queID:Number; // question ID #
private var queType:String; // question type string
private var quePhoto:Boolean; // question photo active
private var answID:Number; // answer ID #
private var itemsXML:XML; // XML for question items
private var itemsData:Array; // array of objects to store question items
private var itemsDataLen:Number; // number of questions
private var itemLoader:MovieClipLoader; // not in use at this time
////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTOR
////////////////////////////////////////////////////////////////////////////////
function MultipleChoice()
{
trace(this);
}
////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
////////////////////////////////////////////////////////////////////////////////
function init(id:Number, type:String, photo:Boolean, answer_id:Number)
{
queID = id;
queType = type;
quePhoto = photo;
answID = answer_id;
itemsLoad();
}
private function itemsLoad():Void
{
itemsXML = new XML();
itemsXML.ignoreWhite = true;
itemsXML.onLoad = Delegate.create(this, itemsProcess);
itemsXML.load(itemsURL + "?quiz_que_id=" + queID);
}
private function itemsProcess(success:Boolean):Void
{
var xPathTemp:String = "/items/item";
var xPathData:Object = XPathAPI.selectNodeList(itemsXML.firstChild, xPathTemp);
itemsData = new Array();
itemsDataLen = xPathData.length;
for (var i:Number = 0; i < itemsDataLen; i++)
{
itemsData.push({
id:xPathData*.attributes.id,
text:xPathData*.childNodes[0].firstChild.nodeValue,
photo_url:xPathData*.childNodes[1].firstChild.nodeValue
});
trace(itemsData*.id);
trace(itemsData*.text);
trace(itemsData*.photo_url);
}
}
////////////////////////////////////////////////////////////////////////////////
// EVENT HANDLERS
////////////////////////////////////////////////////////////////////////////////
}
As I cycle through the questions in the quiz, I will attach a “choices” movieclip which is determined by the question type. A given question type will have 2-3 variants, and the class above will control how the movieclip renders those variants. Here’s the very basic syntax involved:
this.attachMovie("MultipleChoice.mc", "choices", this.getNextHighestDepth()).init(1, "photos", true);
Where 1 = the question ID, “photos” = the multiple choice variant, and true = whether there’s an overarching question photo (independent of the choices).
BACKGROUND: I’ve been in both the Flash Advanced Design and Advanced Application Development training classes, and I’m pretty familiar with classes. What I’m not good at is building them in practice. I know the basics, but I haven’t had need until now to put one together.
Any suggestions for the class I’ve starting working on above are very much appreciated.
IronChefMorimoto