Data-Driven Everything


There are still some missing details. Most important, the answers are dynamic but the questions are not. We correct this by making a question object q with a text variable. This is established in the code on the first frame of the base movie.

ActionScript
 q= new Object(); q.text="Which of these names does<br><b>not</b> belong with the others?" answer0.text="William the Conqueror"; answer1.text="William the Bastard"; answer2.text="William the Bald"; answer2.score=1; answer3.text="William the Duke of Normandy"; stop (); 

The nature of the object q (its text string variable member) is never declared. It is simply constructed when it is invoked. And this works.

Now the hardcoded question in the Start state is replaced with a Dynamic Text field (Figure 3.4). Note the connection to the q.text variable. Note also that HTML is enabled. This will support the HTML tags that we included in the q.text: a line break and the boldface tags around the word "not."

Figure 3.4. The Dynamic Text Field

graphics/03fig04.gif

But the HTML checkbox has an undesirable side effect (at least as of this writing). It causes Flash to ignore the Paragraph settings. The question is no longer centered when it is displayed but rather left justified. To correct this, we can embed HTML alignment tags like

HTML
 <p align='center'> 

Similarly, we might smarten up the text displayed in the Win state. Attach it to a variable called comment . The content of this variable could be established in the movie's initial frame by a simple straightforward assignment:

ActionScript
 comment= "Bald Bill is fake. The other 3 are all the same guy"; 

But we want to add another degree of flexibility to our system. We want to associate the comments to the answers rather than the question.

So far, we have played with a system that provides only a conclusion, a comment seen by the player only after the round is over, in this case after the correct answer is (finally) chosen . We can easily enable this scenario simply by attaching the comment to the correct answer. And since our structure allows multiple correct answers, each can now have a unique comment.

Even more useful is the new ability to associate comments with wrong answers. Jokes, taunts, and real clues can all make a game more lively. So we add a line into the AnswerOption symbol in the second frame ( thinking ). We want to simply use the value of the chosen answer to rewrite the comment that will be displayed:

ActionScript
 _parent.comment = comment; 

This works fine. It updates the comment display with its own local comment. If it has no comment, it updates the variable to be null, and the display is blank. This is the desired behavior.

We can clean up our data by factoring out the HTML centering tags. This is a solid idea since the alignment is related to this particular display far more than to the inherent meaning of the comment. After all, the ideal toward which we are working is display-agnostic content feeding a content- agnostic display. In other words, one part of the program cares solely about the content, and one part cares solely about the display of the content. The content portion will eventually be given to us by XML; the display portion will stick around and eventually become our Flash thin client.

ActionScript
 _parent.comment = " <p align='center'>" + comment + "</p>"; if( score>0 ){    _parent.gotoAndPlay ("Win");   } else         {    _parent.gotoAndPlay ("Lose");  } 

To be able to see the hints and jokes, we need to include the comment display in the Lose state as well as the Win . It is a separate keyframe, rather than an extension of the first (like Score ), because it needs to be repositioned (see Figure 3.5). Since it represents loss, we give it a slightly different color and point size .

Figure 3.5. Rearranging Keyframes

graphics/03fig05.jpg

The organization of layers and keyframes has been cleaned up and we have sneaked in a few sounds. It is still a bit too complex. There is no reason to have separate layers for the question and answers. Layers have no scripting value. They are meaningful only to the editing process: they help us think about, communicate, and especially manipulate the components of a scene. None of this will be made more difficult by collapsing the five layers into a single q & a layer, and the result will be easier to handle.

Now we update the data assignments in the first frame of the movie.

ActionScript
 q.text="Which of these 4 names does<br><b>not</b> belong with the others?" answer0.text="William the Conqueror"; answer1.text="William the Bastard"; answer2.text="William the Bald"; answer2.score=1; answer2.comment="<b>William the Bastard</b> was the illegitimate son of        <br>Robert I, Duke of Normandy and a tanner's daughter. Fatherless        at seven, by fifteen he was acknowledged <b>William the Duke of        Normandy</b>. At age thirty-eight, he persued his claim to the        British throne, and at the Battle of Hastings became <b>William the        Conqueror</b>.<br><br>History records no <b>William the Bald</b>"; answer3.text="William the Duke of Normandy"; answer3.comment="<i>Hint</i>:<br>In 1066, <b>William, the Duke of        Normandy</b> became<br>William I, the King of England"; stop (); 


Flash and XML[c] A Developer[ap]s Guide
Flash and XML[c] A Developer[ap]s Guide
ISBN: 201729202
EAN: N/A
Year: 2005
Pages: 160

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net