Skip to main content
August 27, 2009
Answered

Button on Click, loads a pdf in new window

  • August 27, 2009
  • 2 replies
  • 2095 views

Hello, I am trying find the correct as3 code to make a button on Click, open a pdf in a new window. I have tried different ways, but when I add the code not only does it give me errors, but it makes my swf flip through all the pages instead of stopping on load. It is fine before I enter the code for this button.

Just to let you know, this button is within a movie clip on the main stage. I really wanted it in a MC within another MC, but can't figure out where to put the code.

Should it go on the main timeline, where all the rest of the code is, or should it go within the MC?

Please help! Very frustrated with AS3.

Thanks!

This topic has been closed for replies.
Correct answer

It runs through your frames because the code did not compile properly.

If you have a button, inside some other clip you can do something like:

myClip.myButton.addEventListener(MouseEvent.CLICK, openPDF, false, 0, true);

function openPDF(e:MouseEvent = null){

     navigateToURL(new URLRequest("theURLofThePDF.pdf"), "_blank");
}

2 replies

Ned Murphy
Legend
August 27, 2009

It's always nicer if you can keep your code on the main timeline, but sometimes it's not as convenient.  If the buttons are going to be commanding movement on the main timeline, then the code is easier to work out there.

Show the code you are trying to use that isn't working, and explain how you have that code situated wrt the button.

August 28, 2009

This is all my code. At this point my MC moves through all my content pages. Before I entered the last code (last 3 lines) it worked fine. I'm sure I am missing something simple. With the last piece of code it also gave me the error "1120:access of undefined property TNT_pricelist09. I would imagine because I have to add the folder name to the file name?

Thanks for your help!

home_btn.addEventListener(MouseEvent.CLICK, homePage);

pricing_btn.addEventListener(MouseEvent.CLICK, pricingPage);

about_btn.addEventListener(MouseEvent.CLICK, aboutPage);

contact_btn.addEventListener(MouseEvent.CLICK, contactPage);

function homePage(e:MouseEvent):void

{

content_mc.gotoAndPlay("home");

}

function pricingPage(e:MouseEvent):void

{

content_mc.gotoAndPlay("pricing");

}

function aboutPage(e:MouseEvent):void

{

content_mc.gotoAndPlay("about");

}

function galleryPage(e:MouseEvent):void

{

content_mc.gotoAndPlay("gallery");

}

function contactPage(e:MouseEvent):void

{

content_mc.gotoAndPlay("contact");

}

content_mc.pricePDF_btn.addEventListener(MouseEvent.CLICK, openPDF);

function openPDF(e:MouseEvent):void

{

navigateToURL(URLRequest(TNT_pricelist09.pdf));

}

Correct answer
August 27, 2009

It runs through your frames because the code did not compile properly.

If you have a button, inside some other clip you can do something like:

myClip.myButton.addEventListener(MouseEvent.CLICK, openPDF, false, 0, true);

function openPDF(e:MouseEvent = null){

     navigateToURL(new URLRequest("theURLofThePDF.pdf"), "_blank");
}

August 28, 2009

Thanks dmennonoh,

That's pretty much what I entered. Once I enter that code, I can't get my mc to stop at the home page. All the pages are in a MC called content_mc. Before that code it works fine.

Ned Murphy
Legend
August 28, 2009

Show what code you have now for the pdf linking.  The code you show above is not correct, but would be if you had followed Dave's example.