Controlling ActionScript 3 with dynamically loaded text file

212 views Asked by At

I am successfully able to load an external text file into my Flash movie using AS3. The loaded text file has links which are going to external pdfs. This is working fine, too. Problem is, now I need to call a function inside the Flash file from the links instead of opening the external pdfs. These are DoubleClick ads, in case anyone is familiar.

Here is the AS around a button in the current Flash movie. I have to somehow call a similar function from the text file.

theBut.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_2);

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    var click_url:String = root.loaderInfo.parameters.clickTag;
    if(click_url) {
        navigateToURL(new URLRequest(click_url), '_blank');
    }
}
1

There are 1 answers

0
Vesper On

In this case, you can use the this[string] syntax against root.loaderInfo.parameters. Then, if your loaded text file says there should be a clickTag2 variable, available via string variableName, you use that in your function like this:

function fl_ClickToGoToWebPage_2(event:MouseEvent):void
{
    var click_url:String = root.loaderInfo.parameters[variableName];
    // here you are, now your function queries dynamic vars
    if(click_url) {
        navigateToURL(new URLRequest(click_url), '_blank');
    }
}