Code Snippets   | [Bill's Home]

Reading XML from Flash (Pt. 6)

As much as possible when you design media component, they should be made generic enough, so that they can be easily modified. One of the best ways is to have an XML file which sets the way that the media component is displayed. For example, let's say we have a condition where we either want to show the running score or not. Thus we could set a value in the XML of:

<score>1</score>

If this is included in the XML file, the score box will not be displayed. Thus we could set a binary variable of show_score, so that the score box will only be seen as a background object. This is achieved by setting the alpha property of the score box to 20%:

if (elementType == "score") {
show_score=false;
trace("Score found");
setProperty("/correctbox", _alpha,20);
}

Then where the current score is to be displayed, the show_score value is tested. If it is still true, the score is displayed, else it will not.

if (show_score==true) correctbox.question_text = correct;

The following are the same Flash components, but they read a Flash file which either specifies that they should display the score box, or not.

and the other, with the <score> tag added to the XML file:

If you're interested in resuse and component design in media content, here are a few related papers:

Web composition Markup Language
Component-based WWW design
Reuse in WWW design