Rich Rodecker’s blog on flash, flex, actionscript, javascript, and php, with a dash of randomness
Archive for April, 2006
Argh!! Music in my email!
Apr 30th
Man..today i got an email that had a quick time audio track embedded in it…that’s actually a first for me, and something like that really grinds my gears. Not only was the controller hard to locate in the email, but I double clicked the email to read it…whcih meant that it was actually playing in my preview pane, and also in the new window I opened. great.
copy directory in php
Apr 20th
While trying to figure out how to copy an entire directory to a new location (on the same web server) in php, I came across this function. I took that as a base and modified it to handle premissons better:
-
function copyr($source, $dest){
-
// Simple copy for a file
-
return $c;
-
}
-
-
// Make destination directory
-
}
-
-
// Loop through the folder
-
while (false !== $entry = $dir->read()) {
-
// Skip pointers
-
if ($entry == "." || $entry == "..") {
-
continue;
-
}
-
-
// Deep copy directories
-
if ($dest !== "$source/$entry") {
-
copyr("Â$source/$entry"Â, "$dest/$entry"Â);
-
}
-
}
-
-
// Clean up
-
$dir->close();
-
return true;
-
}
Getting getbytesTotal for dynamically generated images
Apr 17th
*this is a repost...I lost the original in the great blog disaster of '06. I went looking for this info and had to pull it off of google cache, so here it is again.
Ok this one kicked my ass for a few days, I'm posting it here so maybe someone else wont have to go through it.
I was dynamically generating images from a php script using the imagejpeg() function:
-
$filename = $_GET['fileName'];
-
-
-
// Set a maximum height and width
-
$width = $_GET['width'];
-
$height = $_GET['height'];
-
-
-
//a little security
-
}
-
-
// Get new dimensions
-
-
if ($width) {
-
$width = ($height / $height_orig) * $width_orig;
-
} else {
-
$height = ($width / $width_orig) * $height_orig;
-
}
-
-
// Resample
-
$image_p = imagecreatetruecolor($width, $height);
-
$image = imagecreatefromjpeg($filename);
-
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
That worked fine, but if i tried to track the dowload using a bytesLoaded / bytesTotal combo, I was finding the bytesTotal wasn't being set. I figured that was probably a header I needed to set in php, and I was right. You need to set the size in the 'Content-Length' header.
Now my problem was how to get the size of a file you are about to output with the imagejpeg function. There were some notes in the php docs for strlen() that that function will return the size in bites if it is called on a binary object...but that went nowhere.
Turns out, what you need to do is start an output buffer using ob_start(). This will capture all the output from the script instead of outputting it to the browser. After you've created the buffer, you can call imagejpeg() and the image will be outputted to the buffer. After you've outputted the jpg to the buffer, you can call ob_get_length(); and store the size of the output buffer in a variable. After you've got the size of the buffer, you can call ob_end_clean() and discard the buffer....you'll still have access to the variable:
-
imagejpeg($image_p);
Now that you've got what you need (the total bytes of the image), you can add that to the Content-Length header, and output the jpg:
I think it looks a litle more complicated than what it is because I've broken up the code and explained it. Here is the code in it's entirety:
-
$filename = $_GET['fileName'];
-
-
-
// Set a maximum height and width
-
$width = $_GET['width'];
-
$height = $_GET['height'];
-
-
-
//a little security
-
}
-
-
// Get new dimensions
-
-
if ($width) {
-
$width = ($height / $height_orig) * $width_orig;
-
} else {
-
$height = ($width / $width_orig) * $height_orig;
-
}
-
-
// Resample
-
$image_p = imagecreatetruecolor($width, $height);
-
$image = imagecreatefromjpeg($filename);
-
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
-
-
-
imagejpeg($image_p);
-
-
-
imagejpeg($image_p);
-
-
imagedestroy($image_p);
Flash Javascript Integration Kit and security
Apr 13th
I was trying out the FJIK and I couldnt figure out why my calls to an actionscript function were working locally but not in the browser. Figured out I needed to do a System.security.allowDomain() in the swf recieving the function call. I just wanted to post that because i didnt see it in the docs and I couldnt find it while googling.
Freelance flash developers wanted
Apr 9th
I am totally overloaded with contract work/offers and am lookinng to sub-contract out a bunch of work. If you're interested, please email me of leave a comment with some contact info. Just to give you some idea, a lot of the jobs are the types that can probably be busted out in a day or two, with the falsh developer working from designs that have already been created (so there probably wont be too much creative input..just making the stuff functional).
Some requirements:
- Strong knowledge of Actionscript, especially AS2.
- should defintely have experience and capable of working with XML
- Good Communication skills, reliable, professional. I'd like to find someone i can feel comforatble with feeding multiple projects.
- Code samples
Singleton vs Static
Apr 7th
ok, the bitch just posted this on her own blog (sheesh man i feel guilty calling her that, i dont even know her), and I usually don't like just repeating someone else's content, but the I feel the explaination she has posted of using Singletons vs. using Static methods is so great, I just want to post it here as a reference....so go read if you missed it.
Giving away flash/programming books
Apr 1st
I'm clearing out some shelf space and getting rid of a few of my computer-related books. Got a few flash mx books, along with some other random stuff. If anyone wants let me know...I can ship these out to you.
Object Oriented Programming with Actionscript - This book rocked pretty hard in its time...a little outdated since it's AS1 and v1 components, but there's still a bunch of useful info in there.
Flash MX Magic - Again, some good stuff, but a little outdated since its flash mx/AS 1.
Flash MX Games - Actionscript for Artists - with CD. Bought it, and wound up buying the awesome Flash MX Game Design Demystified the next day, so I never actually read this book.
Macromedia Flash MX Developers Guide - ok, this one is like 4 years old, pretty outdated, and only $3 used on amazon. you'd probably only want this if you were going to take another book along with it.
Mac OS X 10.3 Panther - Supposed to be a good book, I wound up not even having to learn the server stuff so I can only go by the reveiws at amazon.
Wireless Messaging Demystified - A good intro into what's going on in when it comes to wireless messaging. More of a general overview of how the systems work rather than a study of WAP or anything like that.
WAP, WML & WMLScript - Another one of those things I was going to do but never wound up doing. I'm not sure how much WAP programming is still going on these days. The picture of the guy in the shades kind of annoys me.
An Invitation to Computer Science - This book is really old..like 10 years old, maybe more. I still found a lot of valuable information as far as what is going on inside the computer, which in turn helped me program better.
Programming and Problem Solving with C++ - Another "gonna" book. I didnt really read it.