A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Best way to open PDFs from Flash presentation

  1. #1
    Member
    Join Date
    Apr 2004
    Posts
    31

    Best way to open PDFs from Flash presentation

    I've been tasked with making a fairly simple Flash presentation that will be published to an exe and put onto a jump drive. I've done this before and at the time I just used the getURL command (IIRC) to open a PDF with a button click. I literally have 100's of PDFs to link to so I was wondering if there is a better way to do it (before I start using my old method)

    I'm using AS3 in Flash CS5. And I am NOT a big Flash user so maybe I just need to resort to the way i did it last time. Was just thinking there might be a more elegant way to approach this...that a novice could handle.

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Well, you can use a loop, but that depends on the link to the PDF files. Respond with some of the PDF URLs
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member
    Join Date
    Apr 2004
    Posts
    31
    Like this?

    am01-antimicrobial_summary.pdf
    am02-bacterial_quantitative_test_methods.pdf
    am03-determination_of_freshness_effects.pdf
    am04-lfreshness_on_demand.pdf
    am05-overview.pdf
    am06-in_the_environment.pdf
    am07-1-am_110_new.pdf
    am07-2-rcd.pdf
    am07-3-fbr-5.pdf

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Well, I thought you'd have am01-am100, but you also have sub parts like am07_1, am07_2 and am07_3, which kinda ruins the method I had in mind. Well, do you have like 100 buttons with on handlers (on(release), on(press), etc.), or do you have 100 buttons with instance names and a huge code on your frame to give each one getURL action? Write back with the method you're using, and if I think what you're using, you can use for loop to loop a code 100 times, and apply to all buttons with different PDF files (those would be stored in an array) when you click on them - just respond with the method you're using
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Member
    Join Date
    Apr 2004
    Posts
    31
    I haven't devised a method yet. I would probably just have individual buttons that each link to a URL/PDF. Some pages of the presentation have around 20 buttons. Some have more or less. I haven't even gotten around to naming instances yet b/c there are so many! I wanted to establish a method before I got too deep and then found a better way.

    And yes. I do have to keep them named more or less descriptively in case someone just wants to browse the PDF directory on the disk.

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Do you want to switch over to AS2, or do you not want to? My skills in AS3 are very poor, and I just hate its strict data typing. I tried writing a code for you, but it gave me so many errors, and I cannot bare with it. In AS3, you can't even place codes ON objects, you have to give them instance names, while in AS2, you can put codes straight on buttons and movieclips, which can save you alot of time by not giving every single button an instance name, and then you can make one function and put that code on every button - and you can also put all the buttons in a movieclip, and then give them actionscript without giving them instance names, nor put codes on the buttons (Flash gives all buttons and movieclips without self defined instance names, default instance names)
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  7. #7
    Member
    Join Date
    Apr 2004
    Posts
    31
    I'm not married to either AS2 or 3 at this point as I haven't even gotten into scripting anything. My original project was AS2 so that would be nice since it would let me reuse some of the stuff. And even though I'm a novice with Flash, I "understand" AS2 much better. It just seems to make more sense to me.

  8. #8
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I'm not married to either
    That made me laugh xD

    It just seems to make more sense to me
    I totally agree!

    -------

    Make an array for all the pdf files, and then make a function with one optional variable for the PDF file reference with corresponding array index, and then open that, and just use the same function on all the buttons with different array indexes to open different PDF files!

    I am pretty sure you didn't understand the above, but here is an example. Let's say you have multiple frames with buttons (like you told), make a new Layer and on its one and only frame extending through all the frames, click on it and open Actions Panel, and in there, make an array with all the PDF file names:

    Actionscript Code:
    pdf_files = [
    "am01-antimicrobial_summary.pdf",
    "am02-bacterial_quantitative_test_methods.pdf",
    "am03-determination_of_freshness_effects.pdf",
    "am04-lfreshness_on_demand.pdf",
    "am05-overview.pdf",
    "am06-in_the_environment.pdf",
    "am07-1-am_110_new.pdf",
    "am07-2-rcd.pdf",
    "am07-3-fbr-5.pdf"]; // and so on

    We simply make an array with all the PDF file names in their own index. After that code, on the same frame, type this function:

    Actionscript Code:
    function btnPDF(pdf_num){
        getURL(pdf_files[pdf_num], "_blank");
    }

    pdf_num is something optional, something you can type yourself when calling the function!

    Now, on each button, just copy and paste this to call the function we made when you press on that particular button:

    Actionscript Code:
    on(press){
        btnPDF(0);
    }

    Where you change 0 to something else on each button. Let's say we put 0 on the first button - then, when you click that button, the first item/index in the array (arrays' index start at 0) which holds the name of the first PDF file, will be opened. If you change 0 to 1 for the second button, the PDF file name at the second item/index in the array will be opened, get it? So you just copy and paste the same code on all the buttons, but change the value to match the file to open. Here is a overview of array indexes:

    Actionscript Code:
    pdf_files = [
    "am01-antimicrobial_summary.pdf", // 0
    "am02-bacterial_quantitative_test_methods.pdf", // 1
    "am03-determination_of_freshness_effects.pdf", // 2
    "am04-lfreshness_on_demand.pdf", // 3
    "am05-overview.pdf", // 4
    "am06-in_the_environment.pdf", // 5
    "am07-1-am_110_new.pdf", // 6
    "am07-2-rcd.pdf", // 7
    "am07-3-fbr-5.pdf"]; // 8

    So basically, it's position of item in array, minus one. So, if you want item 3, which is am03-determination_of_freshness_effects.pdf, you'd think, 3 - 1 = 2 and thus you know that the value to input when calling the function when clicking the buttons, for the third item, is 2

    Hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  9. #9
    Member
    Join Date
    Apr 2004
    Posts
    31
    Wow. That's great. Definitely going to try that today. That would save a LOT of time coding all those buttons!
    Last edited by bazookaman; 10-14-2011 at 06:48 AM.

  10. #10
    Member
    Join Date
    Apr 2004
    Posts
    31
    ok. It's working...for the most part. But I'm having somewhat of a hiccup with it. I've added all the code and created an array with 235 pdfs in it (so far) But everytime I export it, I'm getting all these errors:

    Code:
    Scene=chemicals, layer=chemical nav, frame=10, Line 2
    	')' or ',' expected
    Scene=chemicals, layer=chemical nav, frame=10, Line 3
    	Unexpected '}' encountered
    Scene=chemicals, layer=chemical nav, frame=20, Line 2
    	')' or ',' expected
    Scene=chemicals, layer=chemical nav, frame=20, Line 3
    	Unexpected '}' encountered
    Scene=chemicals, layer=chemical nav, frame=20, Line 2
    	')' or ',' expected
    Scene=chemicals, layer=chemical nav, frame=20, Line 3
    	Unexpected '}' encountered
    Scene=chemicals, layer=chemical nav, frame=20, Line 2
    	')' or ',' expected
    Scene=chemicals, layer=chemical nav, frame=20, Line 3
    	Unexpected '}' encountered

    The first one for example, points to a button with this action on it:
    Code:
    on (release) {
        btnPDF(008);
    }
    which refers to this part in the array:
    Code:
    "links/p3-am07-3-silpure_fbr-5.pdf", // 008
    I'm getting 72 errors out of 235 buttons. So i don't know what is going on. Most of them work just fine. But some don't.

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Oh, I am so sorry. // 008 is the error, I just included it in my last code to show the index. A comment code can't be inside an array - sorry, my fault >.<

    For instance:

    Actionscript Code:
    array = new Array("123456" //888, "424242" //999);

    That doesn't look right, right? Actually, you array would also look horizontal, but since your PDF names are so large, I thought adding a newline/enter after each item would be the most suitable, so, that way it could look like comment codes could be possible. Sorry for the confusion!

    In other words, remove all the // 001, // 002, etc.

    -----------


    What you can do, is to have the array in its own frame in a new layer, and then make it look something like this:

    Actionscript Code:
    pdf_Files = ["PDF1",
    "PDF2",
    "PDF3",
    "PDF4",
    "PDF5"];

    it's the same as before, just that the first file starts on the first line, and then you can just look at the line number on the left side. First line with the first PDF file would be 1, and then just substract 1 from that number, getting 0. So, if you're on PDF5, look at the left side at the line number, and you'll see 5, and then you know the index number is 4. Also, 00 is not necessary, just drop :P
    Last edited by Nig 13; 10-16-2011 at 05:42 AM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  12. #12
    Member
    Join Date
    Apr 2004
    Posts
    31
    alright. I took out all the comments. I've got them in a list anyway. But I still get the same errors. Exactly all 72 of the same errors. Just to be clear, I changed this:

    Code:
    "links/p3-am07-3-silpure_fbr-5.pdf", // 008
    to this

    Code:
    "links/p3-am07-3-silpure_fbr-5.pdf",

  13. #13
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Wait, don't tell me you're using the on(release) code on a frame? If that's what you're doing, then that's the problem - you have to put it on a button, by clicking on it once, opening Actions panel and pasting it there!
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  14. #14
    Member
    Join Date
    Apr 2004
    Posts
    31
    Nope. I know better than that. ; )

    I've got 390 buttons with the on (release) on each that refers to a specific number from the array. The array is on a separate layer that extends the length of the movie.

  15. #15
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Nope. I know better than that. ; )
    Guess I underestimated you, sorry :P

    Well, if I could look at your FLA file, or if you could just copy one of your buttons with one array with one item on a new FLA and send me that, in case you don't want to show me it or if the filesize gets too, that'd be helpuld
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  16. #16
    Member
    Join Date
    Apr 2004
    Posts
    31
    just sent you a PM.

  17. #17
    Member
    Join Date
    Apr 2004
    Posts
    31
    Quote Originally Posted by Nig 13 View Post
    Well, if I could look at your FLA file
    Just wondering if you had any luck figuring out the errors?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center