28 Replies Latest reply on Nov 27, 2008 9:31 AM by whitestar7

    export image in D11

    whitestar7 Level 1
      Hi all,

      I am trying to export cast members when the mouse is clicked, I have been advised to use SharpExport, but SharpExport isnt compatible with D11.

      I have a gallery of images which will go out on a CD-ROM and I am trying to get it working so that when the user clicks on a download button under the image thumbnail it opens a "save" dialogue box and then saves the file to wherever the user selects.

      I know this is probably pretty simple for some of you guys, but I have really tried and not managed to get this to work, thanks for helping
        • 1. Re: export image in D11
          Applied CD Level 1
          Is the thumbnail really what you want to save or is there a full resolution JPG (or whatever) on the CD that you’d like to copy to the user’s HD? If you want to copy an external image file from CD to HD it’s fairly easy with Buddy API’s copyFile method. If you want to convert cast member internal bmp data to another format and save the binary I’m not able to provide much help. I’ll post more info on the Buddy API method if you need or want it.
          • 2. Re: export image in D11
            whitestar7 Level 1
            that would be great, I need to make sure I show a dialogue box asking the user where to save the file, I really appreciate the help
            • 3. Re: export image in D11
              Applied CD Level 1
              If I catch a break during the day I’ll try to post a real script but if you want to get started you need a variable for the sourcePath and another for the destinationPath. The sourcePath would be relative to the movie and append the image folder and filename. For example, if you named your cast members with the same names as the source files:

              On mouseUp me
              sourcePath = _movie.path & “images\” & sprite(me.spriteNum).member.name

              There are much better ways to store the filename reference using properties but the above is short and easy to explain. For the destination path, use Buddy API:

              destinationPath = baGetFolder(“c:\”,”Copy image”,1,”Select folder”,-2,0)

              then you can copy:

              if destinationPath <> “” then
              resultCode = baCopyFile(sourcePath, destinationPath,”IfNewer”)
              end if

              Read up on the Buddy API file methods, there’s lots of things you can do to make this better, for example, use baSysFolder to default the save dialog to My Docs instead of the root level of C:\, also you should handle any copy errors that get returned in resultCode (any number other than 0), you can use baCopyFileProgress to display a copy progress bar etc..
              • 4. Re: export image in D11
                whitestar7 Level 1
                HIya,

                thanks for this, I will give this a shot, if you do get a chance I would be very grateful if you can post a m ore detailed script, thanks for helping me out.
                • 5. export image in D11
                  DAVID NAJAR Level 1
                  Hi,

                  Im using SharpExport Xtra on D11 and everything is ok!!!

                  I leave you my global handler for image save, just put this code on a movie script and call it (ex: saveImageFile(member("MyBitMapMember"), "My image")). I hope this help you.

                  • 6. export image in D11
                    whitestar7 Level 1
                    hiya,

                    I couldnt get this to work, had more luck with APPLIED CD's method, but it doesnt seem to copy the file, here is the code I am using on the button:



                    on mouseEnter me
                    cursor 280
                    end mouseEnter

                    on mouseLeave me
                    cursor -1
                    end mouseLeave


                    on mouseUp me
                    sourcePath = _movie.path & "@:PRODUCT_1:product_1_images:product_1_zoom.jpg"
                    destinationPath = baGetFolder("Macintosh HD:","Copy image",1,"Select folder",-2,0)

                    if destinationPath <> "" then
                    resultCode = baCopyFileProgress(sourcePath, destinationPath,"ALWAYS", "Saving file... ", "Cancel", 0)
                    end if

                    end

                    It opens up the selcet folder window, but nothing copies
                    • 7. Re: export image in D11
                      Applied CD Level 1
                      For the sourcePath you’re using _movie.path and the @ operator which is redundant. Just use the @ operator and you should be fine. If that doesn’t solve the problem check the value of resultCode, it will probably be something other than 0.
                      • 8. Re: export image in D11
                        DAVID NAJAR Level 1
                        Sorry about that, the script and xtra works on Windows.

                        Luck.
                        • 9. Re: export image in D11
                          whitestar7 Level 1
                          Hi Applied,

                          Thanks for this, unfortunately still not having much luck, when I checked the script it said the resultcode was <void>
                          • 10. Re: export image in D11
                            Level 7
                            whitestar7 wrote:
                            > Thanks for this, unfortunately still not having much luck, when I
                            > checked the script it said the resultcode was <void>

                            That would mean that destinationPath="".

                            You perhaps need to use buddyAPI to get a list of the drive names on the Mac
                            before presenting the baGetFolder dialog, although I suggest that just using
                            buddyAPI to get the Desktop folder to supply as the starting folder in the
                            dialog would suffice.

                            Andrew


                            • 11. Re: export image in D11
                              whitestar7 Level 1
                              Hi Andrew,

                              I am not very good at writing lingo (as you might have guessed) how would I ammend my script to do what you say?
                              • 12. Re: export image in D11
                                Level 7
                                whitestar7 wrote:
                                > I am not very good at writing lingo (as you might have guessed) how
                                > would I ammend my script to do what you say?

                                I don't have the Mac BuddyAPI docs to hand, but I think it's the same call
                                as on Windows:

                                ----------------------------------
                                property spriteNum

                                on beginSprite
                                sprite(spriteNum).cursor=280
                                end

                                on endSprite
                                sprite(spriteNum).cursor= -1
                                end

                                on mouseUp me
                                sourcePath = _movie.path &
                                "@:PRODUCT_1:product_1_images:product_1_zoom.jpg"
                                provisionalDestFolder=baSysFolder("desktop")
                                destinationPath = baGetFolder(provisionalDestFolder,"Copy
                                image",1,"Select folder",-2,0)

                                if destinationPath <> "" then
                                resultCode = baCopyFileProgress(sourcePath, destinationPath,"ALWAYS",
                                "Saving
                                file... ", "Cancel", 0)
                                end if

                                end
                                -------------------------------

                                Also, you will get better cursor responsiveness by setting the sprite's
                                cursor rather than using mouseEnter/Leave to set it.

                                I suggest keeping the value of the folder the user chose and starting from
                                there if they can copy more than one file. You can write the code for that
                                :-)

                                HTH

                                Andrew


                                • 13. Re: export image in D11
                                  whitestar7 Level 1
                                  argghhh!!!

                                  I am still getting the resultcode as <void>, this is what I have put in as a behaviour on a shape:

                                  property spriteNum

                                  on beginSprite
                                  sprite(spriteNum).cursor=280
                                  end

                                  on endSprite
                                  sprite(spriteNum).cursor= -1
                                  end

                                  on mouseUp me
                                  sourcePath = _movie.path & "@:PRODUCT_1:product_1_images:product_1_zoom.jpg"
                                  provisionalDestFolder=baSysFolder("desktop")
                                  destinationPath = baGetFolder(provisionalDestFolder,"Copy image",1,"Select folder",-2,0)

                                  if destinationPath <> "" then
                                  resultCode = baCopyFileProgress(sourcePath, destinationPath,"ALWAYS","Saving file... ", "Cancel", 0)
                                  end if

                                  end

                                  I really don't understand what I am doing wrong here, :-(
                                  • 14. Re: export image in D11
                                    Level 7
                                    whitestar7 wrote:
                                    > I am still getting the resultcode as <void>, this is what I have put
                                    > in as a behaviour on a shape:

                                    > sourcePath = _movie.path &
                                    > "@:PRODUCT_1:product_1_images:product_1_zoom.jpg"

                                    > provisionalDestFolder=baSysFolder("desktop")

                                    > destinationPath = baGetFolder(provisionalDestFolder,"Copy image",1,"Select
                                    > folder",-2,0)

                                    Have you tried those lines in the message window, one at a time and checking
                                    the values at each stage?

                                    Andrew


                                    • 15. export image in D11
                                      whitestar7 Level 1
                                      hiya, I gave the message window a go, and everything seems good, the message I got for the result code was:


                                      --> resultCode = baCopyFile(sourcePath, destinationPath,"ALWAYS")
                                      == resultCode = 1

                                      not sure if this is good or bad
                                      • 16. Re: export image in D11
                                        Level 7
                                        A quick glance at the BuddyAPI documentation shows that 1 is the error
                                        code for "Invalid Source file name". I would look into the 1st argument
                                        of baCopyFile and see what is wrong with it. Is it an invalid filename?
                                        Does the file exist?

                                        put this immediately before the copy command:

                                        put sourcePath

                                        Does it return a valid filename? Is it correct? Does that file exist?

                                        As Applied CD said earlier, you do not need the @ sign and _movie.path
                                        in the same command. They mean the same thing, so you may very well be
                                        mangling the actual command by using both.
                                        • 17. Re: export image in D11
                                          Level 7
                                          whitestar7 wrote:
                                          > hiya, I gave the message window a go, and everything seems good, the
                                          > message I got for the result code was:
                                          >
                                          >
                                          > --> resultCode = baCopyFile(sourcePath, destinationPath,"ALWAYS")

                                          This is different code from what you had in your previous posts... you may
                                          have to call that BuddyAPI function with different parameters depending on
                                          the platform.

                                          And a result code of 1 means the source file name was invalid, so something
                                          is wrong there too - I guess you didn't get round to correcting the line

                                          sourcePath = _movie.path & "@:PRODUCT_1:product_1_images:product_1_zoom.jpg"

                                          - didn't the value of sourcePath look wrong in the message window? That
                                          would show you what you need to correct.

                                          I'd rather show you how to find out what is wrong than spoon-feed you all
                                          the answers...

                                          HTH

                                          Andrew


                                          • 18. Re: export image in D11
                                            whitestar7 Level 1
                                            hiya, this is what I get from the message window:

                                            --> put sourcePath = "@:product_1:product_1_images:product_1_pack_zoom.jpg"

                                            I am guessing this means the filename is not valid as when chose a filename which definitely doesnt exist it give the same message
                                            • 19. export image in D11
                                              whitestar7 Level 1
                                              hiya, this is what I get from the message window:

                                              == Script: (member 1 of castLib 1) Handler: mouseUp
                                              --> sourcePath = "@:product_1:product_1_images:product_1_pack_zoom.jpg"
                                              == sourcePath = "@:product_1:product_1_images:product_1_pack_zoom.jpg"
                                              --> provisionalDestFolder=baSysFolder("desktop")
                                              == provisionalDestFolder = "Macintosh HD:Users:2e_admin:Desktop:"
                                              --> destinationPath = baGetFolder(provisionalDestFolder,"Copy image",1,"Select folder",-2,0)
                                              == destinationPath = "Macintosh HD:Users:2e_admin:Desktop:DOWNLOAD:"
                                              --> if destinationPath <> "" then
                                              --> resultCode = baCopyFile(sourcePath, destinationPath,"ALWAYS")
                                              == resultCode = 2
                                              --> end

                                              I am at a loss, because I have used an image which is in the same folder as the director movie and still doesnt work, I understand what you mean about jsut giving the answer and respect that. I am trying hard to do this, and am learning, and I do appreciate the help
                                              • 20. Re: export image in D11
                                                Level 7
                                                whitestar7 wrote:
                                                > hiya, this is what I get from the message window:
                                                >
                                                > == Script: (member 1 of castLib 1) Handler: mouseUp
                                                > --> sourcePath =
                                                > "@:product_1:product_1_images:product_1_pack_zoom.jpg" == sourcePath
                                                > = "@:product_1:product_1_images:product_1_pack_zoom.jpg" -->
                                                > provisionalDestFolder=baSysFolder("desktop") == provisionalDestFolder
                                                > = "Macintosh HD:Users:2e_admin:Desktop:" --> destinationPath =
                                                > baGetFolder(provisionalDestFolder,"Copy image",1,"Select folder",-2,0)
                                                > == destinationPath = "Macintosh HD:Users:2e_admin:Desktop:DOWNLOAD:"
                                                > --> if destinationPath <> "" then
                                                > --> resultCode = baCopyFile(sourcePath, destinationPath,"ALWAYS")
                                                > == resultCode = 2
                                                > --> end

                                                > I am guessing this means the filename is not valid as when chose a
                                                > filename which definitely doesnt exist it give the same message, i
                                                > have tried using an image which is

                                                You've forgotten to tack an actual filename onto the end of destinationPath.

                                                Andrew


                                                • 21. Re: export image in D11
                                                  Applied CD Level 1
                                                  I’m sorry, I forgot about this one “little” point. From the Director Help docs:

                                                  quote:

                                                  Be sure to use the @ symbol when navigating between Director movies or changing the source media of a linked media cast member. The @ symbol does not work when the FileIO extension or other functions are used outside those available within Director.


                                                  Personally, I hate the @ symbol because of exceptions like this and always use _movie.path
                                                  • 22. export image in D11
                                                    whitestar7 Level 1
                                                    Hi Andrew, the actual filename is: "product_1_pack_zoom.jpg" I thought sticking this at the end of the path was correct for the source file, the destinationPath is decided by the user choosing which folder to copy into

                                                    In reference to what Applied has said about the "@" usage, so this would not work with Buddy API and FileIO?

                                                    The end CD-ROM will be used on Macs and PCs, I thought using the "@" will be best for multiplatform
                                                    • 23. Re: export image in D11
                                                      Applied CD Level 1
                                                      quote:

                                                      the destinationPath is decided by the user choosing which folder to copy into

                                                      Not exactly, baGetFolder will give you a folder path but you still need a fully qualified destination path with file name for the copy, so yes, you need to append a file name to the destination folder path.

                                                      As for the @ operator, I'm working in Flash right now so I can't confirm it, but I believe the @ operator will not work in Buddy API, FileIO, or with just about anything that isn't a simple Director keyword.
                                                      • 24. Re: export image in D11
                                                        whitestar7 Level 1
                                                        Hi Guys,

                                                        I have tried as you guys suggested and had no joy, now the resultcode is not <void> but has a value of 2, I am not sure what I am doing wrong here, if you can put some code up here you know works or if there is a test movie I can look at I would appreciate it, or point me to another way to get this working. I need to see where I am going wrong. :-/

                                                        Thanks again for all your help.
                                                        • 25. Re: export image in D11
                                                          whitestar7 Level 1
                                                          Hi,

                                                          I used this function and it worked fine

                                                          set OK = baCopyFile("c:\data\student.dat", "c:\data\backup\student.dat", "IfNewer")

                                                          why would this work and not the other way?
                                                          • 26. Re: export image in D11
                                                            Level 7
                                                            That works because the paths and filenames are correct. The one that
                                                            did not work had an incorrect path or filename. You need to find out
                                                            what the 'sourcePath' variable is set to and correct it. As we have
                                                            mentioned a few times, your syntax is incorrect.
                                                            • 27. export image in D11
                                                              Applied CD Level 1
                                                              OK, try the following, but first, are you using an unregistered copy of Buddy API? If you are, you’re limited to 2 Buddy API functions, the following uses 3 (I think the code you’re using now has 3 functions as well). You could live without the baSysFolder function, just change the line to provisionalDestFolder = “Macintosh HD:” (not good for distribution but it will work for now.) If you decide to register, the lite version would be enough but Buddy API is arguably the most useful xtra ever and the full version is worth the investment.

                                                              Now about the code below. First of all, it’s untested but it should work. If you get an invalid source file name error take a very close look at the path, is it correct? If it looks correct but you’re still getting the error, try putting the JPG file in the same folder as your movie and change the line sourcePath = _movie.path & myFileName. If it works now, try moving the file folder by folder back to its proper home, changing the sourcePath variable to match. If it stops working take a hard look at the sourcePath variable, something is wrong with how you’re specifying the path.

                                                              If the destinationPath continues to be a problem, try temporarily hard coding a destination path, ie: change the line to destinationPath = provisionalDestFolder & myFileName. If your sourcePath is correct this should at least copy the file to your desktop and then we can can figure out why baGetFolder keeps returning “”

                                                              You’ll notice in the error codes that I made codes 6 and 7 negative. That’s because you’re using “ALWAYS” as a parameter in the copy function, so these two codes aren’t really errors, by making them negative I’ve changed them to conditions that will never show.
                                                              • 28. Re: export image in D11
                                                                whitestar7 Level 1
                                                                Hi Applied, thanks for this, will give it a go asap, thanks loads for all your help guys. Its much much appreciated