• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I add a dynamic text file to a button in ActionScript 3?

Guest
May 03, 2009 May 03, 2009

Copy link to clipboard

Copied

Okay. I am trying to load different .txt files on the screen with each button click. I am in my first flash class and have only grasped a little bit of actionscript. If you are proficient in actionscript here is my code.

the button names are: bberk_btn apost_btn phales_btn
the text file names are: bberk.txt apost.txt phales.txt

I have no idea how to connect the text files to the function of each button!
HELP!!!


var content_req1:URLRequest = new URLRequest("text/hales.txt");
var content_ldr:URLLoader = new URLLoader(content_req1);
content_ldr.addEventListener(Event.COM... onComplete1);

function onComplete1(event:Event):void {
about_txt.htmlText = event.target.data;
}


var myLoader:Loader = new Loader();
myLoader.load(new URLRequest("images/phalescpy.jpg"));
addChild(myLoader);
myLoader.x=277.2;
myLoader.y=195.2;


function myhales(event:MouseEvent):void {
myLoader.load(new URLRequest("images/phalescpy.jpg"));
myLoader.x=277.2;
myLoader.y=195.2;

}
function mypost(event:MouseEvent):void {
myLoader.load(new URLRequest("images/apost.jpg"));
myLoader.x=277.2;
myLoader.y=195.2;
about_txt.htmlText = ("text/apost.txt");
}
function myberk(event:MouseEvent):void {
myLoader.load(new URLRequest ("images/bberk.jpg"));
myLoader.x=277.2;
myLoader.y=195.2;
}
hales_btn.addEventListener(MouseEvent.... myhales);
post_btn.addEventListener(MouseEvent.C... mypost);
berk_btn.addEventListener(MouseEvent.C... myberk);

TOPICS
ActionScript

Views

711

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2009 May 03, 2009

Copy link to clipboard

Copied

Although the help implies this should work, and I've seen it written in a book to do things this way, it's not how I do things:

var content_req1:URLRequest = new URLRequest("text/hales.txt");
var content_ldr:URLLoader = new URLLoader(content_req1);
content_ldr.addEventListener(Event.COMPLETE, onComplete1);

Instead, try:

var content_req1:URLRequest = new URLRequest("text/hales.txt");
var content_ldr:URLLoader = new URLLoader();
content_ldr.addEventListener(Event.COMPLETE, onComplete1);

content_ldr1.load(content_req1);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2009 May 03, 2009

Copy link to clipboard

Copied

What I'm trying to do is add a function to each button telling it to load a different external text file.

I tried to do what you asked me to and an error message comes up.

1120: Access of undefined property content_ldr1.

I don't know much about actionscript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 03, 2009 May 03, 2009

Copy link to clipboard

Copied

You must define the var at the top level

var content_ldr1:URLLoader ;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 03, 2009 May 03, 2009

Copy link to clipboard

Copied

Not sure I understand...

another error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at about_fla::MainTimeline/about_fla::frame1()

I just want the external text files to be connected to the functions of the buttons:  bberk_btn; apost_btn; phales_btn

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 03, 2009 May 03, 2009

Copy link to clipboard

Copied

LATEST

In that case I recommend you to read about the navigateToURL in the documentation files to better understand how it works and how to use it my friend.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines