Hi there,
I am currently learning AS3 and have a whale of a time! (hmmm)
Anyway, I am trying to create an external class that will load external text into a movie, so I can re-use this again and again. So I have a flash movie with a textField in it with an instance name of exText_txt.
In the fla I have the following actionscript to load the new class and put the text and cssfile into it:
import bobcooper.ExternalText;
var cssPath:String = "css/flashStyles.css";
var exampleText:String = "<h1>This is a headline</h1>" + "This is a line of text. <span class=\"bluetext\">" + "This line of text is colored blue.</span>";
var externalText:ExternalText = new ExternalText(exampleText, cssPath);
externalText.getTextFile(null);
I then have an as file called ExternalText.as with the following code:
package bobcooper
{
import flash.display.*;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class ExternalText
{
var loader:URLLoader;
var exampleText:String;
var cssPath:String;
public function ExternalText(et:String, cp:String):void
{
exampleText = et;
cssPath = cp;
}
public function getTextFile(e:Event):void{
var req:URLRequest = new URLRequest(cssPath);
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onCSSFileLoaded);
loader.load(req);
}
public function onCSSFileLoaded(event:Event):void
{
var sheet:StyleSheet = new StyleSheet();
sheet.parseCSS(loader.data);
exText_txt.styleSheet = sheet;
exText_txt.htmlText = exampleText;
}
}
}
However I keep on getting the following error:
1120: Access of undefined property exText_txt.
So what I need to know is how / where do I define exText_txt?
Eventually the plan is to have the textfield within a movieclip on the stage so I can mask it and scroll it etc, so I would also like to know how to reference a movieclip from an external class.
Thanks for your help,
Bob