samedi 25 juin 2016

AS3 Loading dynamically named text files

I have a preload movie that loads an interface. In the interface I have many buttons. When I click on a button I want to load a text file into a movie called "TextMovie.swf". I want to be able to click on a button, take the name of the button and load a text file that is the same name as the button instance, and have the window appear close to the mouse click. There will be hundreds of buttons and hundreds of text files. I'm sure this is easy for some. Here is the loader for a button:

button_1.addEventListener(MouseEvent.CLICK, fl_ClickToPosition_2);

function fl_ClickToPosition_2(event:MouseEvent):void 
{
var my2ndLoader:Loader = new Loader();
var url2:URLRequest = new URLRequest("TextMovie.swf");
my2ndLoader.load(url2);
addChild(my2ndLoader);
my2ndLoader.x = 200;    
my2ndLoader.y = 10;

}

Then in the TextMovie.swf I have:

import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.StyleSheet;

var css:StyleSheet = new StyleSheet();
css.setStyle("a:hover", {textDecoration:"underline"});

var textLoader: URLLoader = new URLLoader();
textLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

textLoader.addEventListener(Event.COMPLETE, textLoaded);

loadText();

function textLoaded(evt: Event): void {
title_txt.htmlText = textLoader.data.txtTitle;
main_txt.htmlText = textLoader.data.txtBody;
URL_txt.htmlText = textLoader.data.txtURL;
URL_txt.styleSheet = css
}

function loadText(): void {
// var fileName: String = "assets/test_01.txt";
var fileName: String = "assets/" +  +  ".txt";
textLoader.load(new URLRequest(fileName));
}

I'm not sure how to get the name of the button I pushed and apply it to the string that will load the correct text file. I also can't get the window to appear close to the mouse click. Right now I just have it set with an x and y for testing.

I know it's a lot but thanks for any help.

Aucun commentaire:

Enregistrer un commentaire