Markus_D
February 15th, 2008, 11:14 AM
I have a very basic flash document, with a dynamic text field called myText, and a script to load an external html-file into that field. The script is from a tutorial somewhere, so I'm not 100% sure it's optimal, but it works. What I want to do is modify this code so that a clicking a button in this document will switch the input file from demo.html to another HTML-file, say demo2.html.
var url:String = "demo.html";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));
function completeHandler(event:Event):void {
myText.htmlText = event.target.data as String;
}
I'm very much a beginner, just getting to grips with the language, and programming in general, so the Adobe Developer support is way beyond my comprehension.
I think I understand the first five lines and what they do, but the completeHandler-stuff is kinda beyond me. Which I assume is why I'm not getting it to work.
I've added a button (instance name "btn"), and attempted to use a MouseEvent listener to call a function I named "otherText", and that works fine, the listener checks out, but I don't know how to write the function to actually redefine the input. I tried just copying and pasting the code into the function and renaming the variables, but that was doomed to fail. Here's an example of that botched attempt:
var url:String = "demo.html";
var url2:String = "demo2.html";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));
function completeHandler(event:Event):void {
myText.htmlText = event.target.data as String;
}
btn1.addEventListener(MouseEvent.CLICK, otherText);
function otherText(evt:MouseEvent):void {
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url2));
function completeHandler(event:Event):void {
myText.htmlText = event.target.data as String;
}
}
So as you can see, I'm screwed. Any links to understandable tutorials would be appreciated. I've googled my *** off and can't come up with anything that's relevant to AS3 and in my league of comprehension.
var url:String = "demo.html";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));
function completeHandler(event:Event):void {
myText.htmlText = event.target.data as String;
}
I'm very much a beginner, just getting to grips with the language, and programming in general, so the Adobe Developer support is way beyond my comprehension.
I think I understand the first five lines and what they do, but the completeHandler-stuff is kinda beyond me. Which I assume is why I'm not getting it to work.
I've added a button (instance name "btn"), and attempted to use a MouseEvent listener to call a function I named "otherText", and that works fine, the listener checks out, but I don't know how to write the function to actually redefine the input. I tried just copying and pasting the code into the function and renaming the variables, but that was doomed to fail. Here's an example of that botched attempt:
var url:String = "demo.html";
var url2:String = "demo2.html";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));
function completeHandler(event:Event):void {
myText.htmlText = event.target.data as String;
}
btn1.addEventListener(MouseEvent.CLICK, otherText);
function otherText(evt:MouseEvent):void {
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url2));
function completeHandler(event:Event):void {
myText.htmlText = event.target.data as String;
}
}
So as you can see, I'm screwed. Any links to understandable tutorials would be appreciated. I've googled my *** off and can't come up with anything that's relevant to AS3 and in my league of comprehension.