# Switching external HTML files in a dynamic text-field? (AS3)

**URL:** <https://forum.kirupa.com/t/switching-external-html-files-in-a-dynamic-text-field-as3/252068>\
**Category:** Uncategorized\
**Created:** [February 15, 2008, 3:14pm UTC](https://forum.kirupa.com/t/switching-external-html-files-in-a-dynamic-text-field-as3/252068 "2008-02-15T15:14:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markus\_D](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@Markus\_D](https://forum.kirupa.com/u/Markus_D)\
**Post date:** [February 15, 2008, 3:14pm UTC](https://forum.kirupa.com/t/switching-external-html-files-in-a-dynamic-text-field-as3/252068/1 "2008-02-15T15:14:25Z")

</div>

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.
