Sunday, 10 April 2011

Word of the day in Actionscript 3

In this tutorial you will learn how to create a Word of the day application. The words are provided by the Yahoo word of the day RSS feed. Every day you will see a different word and definition in the application.

Word of the day in Actionscript 3

Step 1

Open a new Actionscript 3 file with the stage dimensions 400x250. Give the document class the name: 'WordDay'

Step 2

Select the Text tool with dynamic text and drag three text fields on the stage. Give them the instance names: title_txt, des_txt, and date_txt accordingly.

Step 3

Open a new AS3 class file and save the file as ‘WordDay’ then enter the following code:

package {

import flash.display.MovieClip;

public class WordDay extends MovieClip {

private var xml:XML;
private var titleText:String;
private var descriptionText:String;
private var loader:URLLoader;

public function WordDay() {
//Create a new instance of the URLLoader class and load the words rss feed.
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(new URLRequest(""));

private function xmlLoaded(e:Event):void {
loader.removeEventListener(Event.COMPLETE, xmlLoaded);
xml = new XML(;
titleText =;
descriptionText =;

//This function displays the parsed xml into the text fields.
private function addText():void {
title_txt.text = titleText.substring(0,titleText.indexOf("-"));
des_txt.text   = descriptionText;
date_txt.text  = titleText.substring(titleText.indexOf("-") + 2,titleText.length);

Note, that I have separated the title and date into two different text fields using the substring() method. If you trace out ‘titleText’ inside the xmlLoaded function you will see that the title and date are joined together.

Step 4

Test your movie clip Ctrl + Enter.


trulybrilliant109 26 August 2011 at 08:35  

When I create this it gives the error message: "Scene 1, Layer scripts, Frame 1, Line 2 ... 1037: Packages cannot be nested.

iliketo 27 August 2011 at 04:22  


It looks like you have added the code into the timeline.

Add the code into a class file and set the document class to WordDay.

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP