Monday, June 30, 2008

Resource of web dev bits n pieces

Javascript, CSS, HTML, etc nicely laid out 

Wednesday, June 25, 2008

Flash CD-ROM - Opening PDFs cross platform

This info works for me using Adobe Flash CS3 and Actionscript 2.0 (AS2) and a Mac Powerbook G4 OS x 10.4.11. Make sure you read the Known Bugs at the bottom of the page before pulling your hair out and retiring to a Armish commune...
If you notice errors when using this info please correct and post into a comment.

How to get PDFs opening in Acrobat (or a Word .doc opening in Word and so on) from a standalone flash projector such as would go on a CD-ROM. And you need your CD-ROM to be cross platform.

scroll down and download the file there called example.zip
(Cant really remember but think that is the original fscommand example folder i used to start working with. There is possibly another one out there with all the cross platform files called "thefile" but i couldnt find it.)
Look in that example to get your head around what you need to do in your own flash project. Then copy the fscommand folder into your own projects root folder and rename the files to thefile.exe, thefile.bat, thefile.pdf.

then follow this....
(Maybe I'm paranoid but its a good idea if you are copying and pasting code from a blog, to paste the code into the TextEdit Application or similiar and go Format>Make Plain Text, then copy paste that into Flash. Otherwise there could be some hidden text formatting voodoo messing up your scripts.)

Heres the Actionscript for opening a pdf from a button in a flash standalone projector (AS2). In the examples and instructions the pdf file we want to open is called thefile.pdf:

Put the below into a frame script:

//this helps open the pdf cross platform
function SmartExec(target)
{
platform = substring(getVersion(), 1,3);

if (platform == "WIN")
{
// we're running on Windows, target an EXE file
fscommand("exec", target + ".exe");
}
else
{
// we're running on a MAC, target an AppleScript file
fscommand("exec", target + "_script.app");
}
}
//for info see http://board.flashkit.com/board/showthread.php?t=756863. I added in the .app extention after _script myself, because it didn't work without it as was published elsewhere.

//this is the button on the stage that the user clicks when they want to open the pdf. You'll need to make this button. It has an instance name of "pdf_btn1"
pdf_btn1.onRelease = function():Void
{
SmartExec("thefile");
}

//this is the end of the frame script yo!

How to make the pdf opening scripts (.app, .exe, .bat)
Mac (.app):
1/ copy this applescript below:

--set the name of the file to open
property fileName : "thefile.pdf"

--get the path to the containing folder
set myPath to (path to me as string)
set AppleScript's text item delimiters to ":"

set the parentFolder to ¬
((text items 1 thru -2 of myPath) & "") as string

set AppleScript's text item delimiters to ""

-- find the flash file

try
set targetFile to alias (the parentFolder & fileName)
on error
--ie if there's no file here by this name, it will quit.
return quit
end try

-- open the file

tell application "Finder"
open file targetFile
end tell

-- the applescript has ended yo!

2/ copy paste that script above into applescripts 'script editor' (applications>applescript>script editor) if your not on a mac youll need to google how to make and applescript on a pc at this point.
3/ change "thefile.pdf" to whatever your pdfs file name is, or leave it as thefile.pdf for now until youve done a test.
4/ file > save as
5/ name your file your pdf files name then add '_script' at the end of your file name and before the file extention. so if your pdf is called thefile.pdf then your applescript will be called thefile_script.app
6/ while still in the save as dialogue box, at file format dropdown choose 'application'. at options, tick 'run only'. click save. save into your fscommand folder where your pdf is too.

Windows (.bat,.exe):
1/ simply change the .exe filename to your pdfs filename. so if you pdf is called thefile.pdf, then change your exes name to thefile.exe.
2/ to make the bat file, simply open the bat file in this template folder in textedit, change the filename in its script to your pdfs filename, then go format > make plain text, then go file> save as and change the filename to your pdfs filename and .bat. ie thefile.bat. you will need to untick the option at the bottom that says "if no extention is used use .txt." or it will mess up your filename. Choose plain text encoding Western Windows Latin 1. save into your fscommand folder with your pdf file.

Known Bugs:
i read it here: http://www.atomiksoftware.com/fire-up/index.htm
theres a bug in flash player 9 when your authoring in cs3 on mac, which will stop the pdf from opening. Even when you say you want to publish your swf file to flash 8, you projector publishes to your most recent flash player version, which is probably 9. To get around it, you need to publish your projector to flash player 8.
To do this you will need to download the standalone flash player 8 from adobe. http://www.adobe.com/support/flashplayer/downloads.html
You can download and run the old player from just a desktop folder, it dosnt interfere with other stuff. Drag it to the dock so you can use it for quick opening.
Now in flash, make your publish settings to be to flash player 8, and a swf, and dont tick macintosh projector. (you can do a windows one if you want). then publish.
then in the finder navigate to where you saved your swf, then drag that swf into the shortcut you just created in the dock for the SAflashplayer 8, to open the swf in that version of flash player.
Then when youve got it open, go file> create projector. Then, open your projector and test launching the pdf, it should now launch your pdf using applescript properly.
test on a pc also, although this bug didn't occur on a pc last time. Think because the proxy.exe (yours was called test.exe when you downloaded it) has a fix in it already
http://www.northcode.com/blog.php/2007/08/14/FSCommand-EXEC-is-Broken-in-Flash-CS3

File name length issues / bugs?
So I thought I had documented the definitive process, then I come across something else! There is a restriction on how long your .pdf or .doc or whatever filenames can be.
For example I can open a file with these names:
21characters111111111.doc
20characters11111111.doc
19characters1111111.doc
and under

But cant open a files with these names:
22characters1111111111.doc
23characters11111111111.doc
24characters111111111111.doc
and over

So before you go making all your scripts, exes, bats etc, you'll need to re-name all your files to be under 22 characters long not including the file extension .doc, .pdf etc.

Yeh I know I'm screaming on the inside too because I just finished making them all.
NOT TESTED on a PC or from a CD-Rom on a mac. I doubt testing it from a CD-ROM would make a difference. Even if it did, its not any help, because I want to proof my projectors as standalones as I'm working, not burn a CD every time I want to proof it.

And Lastly... make sure your pdfs, exes, bats, .apps are all inside one folder called fscommand. This fscommand folder should live in your root folder, or at the same level as the flash projector file that want to open the pdf.

Ill be posting the definitive 'How to burn a cross platform CD-ROM on a mac' very soon, which will make this info complete.