Copy link to clipboard
Copied
I am making a SWF with a menu to load a list of PDFs. My code is giving me issues. I have two PDFs in the list and when I click each they both load the same thing even though they are calling to different files and they are both different buttons with different instances. Here is my code:
hammer_crusher_load.addEventListener(MouseEvent.CLICK, goPDF);
crush_retro_load.addEventListener(MouseEvent.CLICK, goPDF);
function goPDF(event:MouseEvent):void
{
var url:String = "Brochures/Crushing/EVHammerImpactCrusherlowres.pdf";
var url:String = "Brochures/Crushing/EVcrusherretrofit.pdf";
var request:URLRequest = new URLRequest(url);
navigateToURL(request);
}
When I test the SWF I get this error:
Scene 1, Layer 'Actions', Frame 10, Line 7 Warning 3596: Duplicate variable definition.
I dont know how else to write this. If someone could show me what I am doing wrong I would appreciate it. Thanks.
the second bit of code i have tried that still wont work right is:
hammer_crusher_load.addEventListener(MouseEvent.CLICK, goPDF);
function goPDF(event:MouseEvent):void
{
var url:String = "Brochures/Crushing/EVHammerImpactCrusherlowres.pdf";
var request:URLRequest = new URLRequest(url);
navigateToURL(request);
}
crush_retro_load.addEventListener(MouseEvent.CLICK, goPDF);
{
var url:String = "Brochures/Crushing/EVcrusherretrofit.pdf";
var request:URLRequest = new URLRequest(url);
navigateToURL(request);
}
Here are two of many ways to accomplish that:
Option 1:
...hammer_crusher_load.addEventListener(MouseEvent.CLICK, goPDF);
crush_retro_load.addEventListener(MouseEvent.CLICK, goPDF);
function goPDF(e:MouseEvent):void
{
var url:String;
switch (e.currentTarget)
{
case hammer_crusher_load:
url = "Brochures/Crushing/EVHammerImpactCrusherlowres.pdf";
break;
case crush_retro_load:
Copy link to clipboard
Copied
Here are two of many ways to accomplish that:
Option 1:
hammer_crusher_load.addEventListener(MouseEvent.CLICK, goPDF);
crush_retro_load.addEventListener(MouseEvent.CLICK, goPDF);
function goPDF(e:MouseEvent):void
{
var url:String;
switch (e.currentTarget)
{
case hammer_crusher_load:
url = "Brochures/Crushing/EVHammerImpactCrusherlowres.pdf";
break;
case crush_retro_load:
url = "Brochures/Crushing/EVcrusherretrofit.pdf";
break;
}
if (url)
{
var request:URLRequest = new URLRequest(url);
navigateToURL(request);
}
}
Option 2:
import flash.utils.Dictionary;
hammer_crusher_load.addEventListener(MouseEvent.CLICK, goPDF);
crush_retro_load.addEventListener(MouseEvent.CLICK, goPDF);
var urlMap:Dictionary = new Dictionary();
urlMap[hammer_crusher_load] = "Brochures/Crushing/EVHammerImpactCrusherlowres.pdf";
urlMap[crush_retro_load] = "Brochures/Crushing/EVcrusherretrofit.pdf";
function goPDF(e:MouseEvent):void
{
var url:String = urlMap[e.currentTarget];
if (url)
navigateToURL(new URLRequest(url));
}
Copy link to clipboard
Copied
Thank you so much you are a life saver. I will play with both of these.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now