Archive for May, 2008

Real Dynamic Text with Flash CS3

Dynamic text feature in flash cs3 is misleading. Now for those who do not understand what dynamic text is, here’s a little background

Static Text – This is basically any text you drag & drop, put into components on the stage.

Dynamic Text – This is the process by which you create an instance of a text-type component, give it an instance name, then reference text through ActionScript – through the .text or .htmlText properties

But there’s is a problem with this solution, you have to recompile flash!

Real Dynamic Text – This is the process where your instances of text are referenced by a data source – such as XML. Why is this good? Because to change content in your flash, you no longer have to recompile flash. You simply have to change the data in the XML

Here’s some code by which you can reference: – XML ~ E4XSyntax

import flash.events.*;
import flash.net.*;

private var xmlFile:XML;
private var xmlRequest:URLRequest;
private var xmlLoader:URLLoader;

public function someConstructor() {

xmlRequest = new URLRequest(“xmlFileNameInSameDirectory.xml”);
xmlLoader = new URLLoader();
xmlLoader.load(xmlRequest);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoadingComplete);
}
private function xmlLoadingComplete(event: Event):void {

xmlFile = new XML(xmlLoader.data);

//Component instance name from Stage
//Here just set any text you wish to be “real dynamic” – in the place of your XML file.
text_mc.text = xml.*[0];
}