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

question about pdf loading

Guest
Jan 22, 2014 Jan 22, 2014

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);

}

TOPICS
ActionScript
623
Translate
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

correct answers 1 Correct answer

LEGEND , Jan 22, 2014 Jan 22, 2014

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:

   

...
Translate
LEGEND ,
Jan 22, 2014 Jan 22, 2014

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));

}

Translate
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
Jan 23, 2014 Jan 23, 2014
LATEST

Thank you so much you are a life saver. I will play with both of these.

Translate
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