Learn Flash Lesson 3 : Categorical Question

In the previous two articles we saw how to pass things from a flash object to data collection server and back again. In this article we will make a  categorical style question in flash and link it to our data collection survey. We will start with passing the data back to a text box and then  progress onto linking it to a categorical question.

The first thing we need to do is it take a copy of our Lesson 2 files. We created a “FlashLesson3” directory and called our files  “Flash.html”,”FlashLesson3.fla” , “FlashLesson3.mdd” and “FlashLesson3.swf”. Once you have done this , create your Categorical question, we have  chosen to produce something like this. We just used buttons and text labels and manualy placed them on the stage where we wanted them.

The Look
The Look

In this example we removed the next button, the idea here is that it is a single response question and when you select the response you want, it will automatically progress onto the next question. Once we have our look and feel we need to start thinking about the action script we need. To make  our life easy we copied the previous examples so in the Actions window we have all the basic script. To add onClick functions to each of the buttons we  must first give all the buttons an instance name. We used , “bCar, bBoat, bHouse, bDog & bCat”.

Next we modified our script and added the EventListener for each button.

bCar.addEventListener("click", clickCar);
bBoat.addEventListener("click", clickBoat);
bHouse.addEventListener("click", clickHouse);
bDog.addEventListener("click", clickDog);
bCat.addEventListener("click", clickCat);

What this is saying is that when the object bCar is clicked run the function ClickCar. Now at this stage we don’t have a ClickCar function so we need  to modify the clickSend function

 function clickSend(event:Event):void
 {
 var jsArgument:String = SendIt.text;
 var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument);
 }

to look like this one.

 function clickCar(event:Event):void
 {
 SendIt.text = "{Car}";
 var result:Object = ExternalInterface.call("getTextFromFlash", SendIt.text);
 }

Then take a copy of this clickCar function an create a function for each button. An example of the clickBoat function would be,

 function clickBoat(event:Event):void
 {
 SendIt.text = "{Boat}";
 var result:Object = ExternalInterface.call("getTextFromFlash", SendIt.text);
 }

Once we have all the functions we need we can publish our flash object and check to see what happens when we click a button. If all is ok , then we  should see that when we click one of the buttons the words for that option appear in the text box in the flash object as show in the image.

Final Look
Final Look

Now we need to create an MDD file and add the template. The metadata for our mdd file should look like this.

Metadata(en-AU, Question, Label)
    Flash "Please enter your Answer"
    text;
    Q1 "Please select one item that you own."
    categorical [1..1]
    {
        Car "Car",
        Boat "Boat",
        House "House",
        Dog "Dog",
        Cat "Cat"
    };
End Metadata

and your routing to start with should look like this.

Routing(Web)
 FLash_Answer.LayoutTemplate = "Flash.html"
 FLash_Answer.ask()
 Q1 = CCategorical(FLash_Answer)
 Q1.Show()
End Routing

Next open up your flash.html file and do a search and replace and change all mentions of “FlashLesson2” to “FlashLesson3”. Then if you just save  everything and run this survey in Professional you will see that everything works, when we click on an item in the flash object we are moved onto the  next question that shows us the chosen answer. This method will help us when it comes to reporting as we have already set the Text answer to a  Categorical question using iom scripting. Taking this a stage further as we add questions and flash objects to our script we will ( apart from create  the objects themselves ) just need to have something like this.

Routing(Web)
 FLash_Answer.LayoutTemplate = "Flash.html"
 FLash_Answer.ask()
 Q1 = CCategorical(FLash_Answer)
 FLash_Answer = ""
 FLash_Answer.ask()
 Q2 = CCategorical(FLash_Answer)
 FLash_Answer = ""
 FLash_Answer.ask()
Q3 = CCategorical(FLash_Answer)
End Routing

Hopefully by now you have the general idea on how you could integrate flash and HTML, we have only touched the very tip of what you can do with  flash, but with a few Google searches you can quite easily find examples to create all sorts of question types. In our next article we are going to  look at a way by which we can perhaps make this concept we have come up with a little more generic.

1 thought on “Learn Flash Lesson 3 : Categorical Question”

Leave a Comment

%d bloggers like this: