PHP output and flash.net.URLLoader bytesTotal property
I hit a problem this week that had me stumped (what’s new?). So, I put on my scuba gear and dove into the code….
More after the jump… (more…)
I hit a problem this week that had me stumped (what’s new?). So, I put on my scuba gear and dove into the code….
More after the jump… (more…)
In a current AS3 project I am maintaining information about images in a custom Image class that extends Object. One of the properties of an Image instance is .orderNum. When I retrieve a list of Image instances, I store them in an Array instance. I need to sort the images within the array by the .orderNum property. Enter the Array.sortOn() method…
//Create an array to hold Objects representing images
var images:Array = new Array();
//Create some objects representing images
images[0] = new Object();
images[0].filename = 'cat.jpg';
images[0].orderNum = 0;
images[1] = new Object();
images[1].filename = 'dog.jpg';
images[1].orderNum = 2;
images[2] = new Object();
images[2].filename = 'dragon.jpg';
images[2].orderNum = 1;
display(images);
/*
Contents of images:
images[0].orderNum = 0
images[1].orderNum = 2
images[2].orderNum = 1
*/
//Sort the images array by the "orderNum" property of each Object value
images.sortOn("orderNum");
display(images);
/*
Contents of images:
images[0].orderNum = 0
images[1].orderNum = 1
images[2].orderNum = 2
*/
function display(images:Array):void
{
trace('Contents of images:');
for(var i:int = 0; i < images.length; i++)
{
trace('images[' + i + '].orderNum = ' + images[i].orderNum);
}
}
I just learned how to embed a font into an AS3 class I am developing—without doing anything in the Flash IDE! Credit goes to this blog and this answer on stackoverflow.com.
Where’s your font file?
Find the location of the truetype (TTF) file for the font you are going to embed. I am using Futura Std Book, and it’s truetype file is located at C:\Windows\Fonts\FuturaStd-Book.ttf.
The code
Add the following code to your AS3 class. I added mine alongside my class property definitions:
[Embed(source="C:\WINDOWS\Fonts\FuturaStd-Book.ttf", fontFamily="Futura Std Book")]
Note: The fontFamily variable in the above code must be the family name for your font. So, for example, I had to use “Futura Std Book”. I could not have chosen something custom like “Futura” or “futurefont” or “bacon”. Mmmm… bacon…
This was a bit of a pain because the font file did not have spaces (“FuturaStd-Book.ttf”), but if you are on Windows, you can double-click your TTF file and it will see the “Font name” that you need to use. Here’s a screenshot from my computer:
Setup the TextFormat instance
//Imports import flash.text.TextFormat; import flash.text.AntiAliasType; import flash.text.TextField; //Declare your TextFormat instance protected var format:TextFormat = new TextFormat(); //Setup the font with your TextFormat instance //This must be exactly what you set as "fontFamily" in the Embed code format.font = "Futura Std Book"; format.embedFonts = true; format.antiAliasType = AntiAliasType.ADVANCED; format.size = 14; var textField:TextField = new TextField(); textField.setTextFormat(format); textField.text = 'Awesome!';
I encountered my first Security Sandbox error while testing an AS3 project on the production server.
I have a primary SWF called top.swf that loads an XML file with a list of URLs for other SWF files that will be loaded as sub-SWFs in top.swf.
The XML file loads fine (it is located in a directory below top.swf). The issue is in the loading of the sub-SWFs (all located in a directory below top.swf called swf. To avoid this error/security violation, add the following line to the constructor of each of your sub-SWF’s Document class:
Security.allowDomain('*');
You will need to add the following import to each of the Document classes as well:
import flash.system.Security;
Note: You must have the Flash Debug Player installed to catch Security Sandbox violations in your browser.
I am working on an AS3 project and developing it with the Flash CS3 IDE and FlashDevelop 3.0.6. I write all of the code in FlashDevelop and use the Flash IDE to create visual elements that would be a pain in the arse to code.
When using flash.net.URLLoader to load external XML data and working on the local server, if the XML is updated between compiles, Flash CS3 will keep loading the previous version. In my case I have a PHP file that is called and the PHP file outputs XML.
To prevent the cache issue:
Append a randomly generated number to the URL string that points to the XML file (or, in my case, the PHP file).
var xmlUrl:String = 'some_url.php'; var randomNumber:int = Math.round(Math.random()*100000000); xmlUrl += '?prevent_cache=' + randomNumber;
I devised a way to store functions in an array and then call them later. I used this for implementing a loading queue that calls each consecutive function when an asynchronous load process completes.
var functionsArray:Array = new Array();
register(testA);
register(testB);
for each(var f:Function in functionsArray)
{
f();
}
function register(f:Function):void
{
functionsArray.push(f);
}
function testA():void
{
trace('testA() called.');
}
function testB():void
{
trace('testB() called.');
}
I have Dreamweaver CS3 installed on Windows Vista (Home Premium). It turns out that if you want Dreamweaver to color *.inc files as it does *.php files, you need to add inc to the file called MMDocumentTypes.xml. The document is located at C:\Program Files\Adobe\Adobe Dreamweaver CS3\configuration\DocumentTypes\MMDocumentTypes.xml on my machine.
Edit the winfileextension and macfileextension attributes to include inc.
Before:
<documenttype id="PHP_MySQL" servermodel="PHP MySQL" internaltype="Dynamic" winfileextension="php,php3,php4,php5" macfileextension="php,php3,php4,php5" file="Default.php" writebyteordermark="false">
After:
<documenttype id="PHP_MySQL" servermodel="PHP MySQL" internaltype="Dynamic" winfileextension="php,php3,php4,php5,inc" macfileextension="php,php3,php4,php5,inc" file="Default.php" writebyteordermark="false">
Save the file and restart Dreamweaver. Worked for me! Thanks to John T on superuser for this solution.
I have been having some serious issues building a thorough file upload script for JPEG files using PHP. It is surprising to me how little information I can find about writing upload scripts that check errors and try to make the experience as user-friendly as possible when errors occur.
I will document my discoveries in a series of posts, starting with this one.
The post_max_size setting in php.ini:
Per Matthew Flaschen’s answer to my question “What exactly does it mean when $_FILES is empty?”, it is most likely due to the size of the to-be-uploaded-file exceeding what post_max_size is set to in php.ini. This was the problem when I tried uploading a 17MB TIFF image file to test what would happen on the user’s end. Specifically, the $_FILES superglobal (and $_POST) were returning empty. Had I read through this PHP manual page, I would have figured that out (scroll down to post_max_size in that link).
So, now I check if $_POST or $_FILES are empty with:
if(empty($_POST) || empty($_FILES))
{
//Do some friendly error-checking here
}
As of right now, I am displaying an error recommending that the user check the size of their file. In the current project I am working on, it is very likely that the client is attempting to upload original high-resolution image files (which are typically well over the 2M default upload_max_filesize and most definitely well over the 8M default post_max_size in php.ini).
I am using
unzip
for the first time in Linux. I had to apt-get install unzip zip first.
I am installing WordPress 2.9.2 on my development server, which means I downloaded the WordPress ZIP file and FTPed it to my server. I found this tutorial which led me to the proper command to unzip WordPress into a specified directory:
unzip wordpress-2.9.2.zip -d /var/www
This gave me
/var/www/wordpress
, which I renamed to
/var/www/miketmoore
by using
mv /var/www/wordpress /var/www/miketmoore
.
Yay for zipping!
I recently bartered for a Dell Dimension 4500 and set it up as a LAMP server. I started with Ubuntu Server Edition 10.04 (Lucid Lynx) and then switched to Debian server, but had internet connection issues with Debian, so I switched back to Ubuntu and haven’t had any issues. This is the primary resource that I used for setting up the server.
This is my first direct experience with Linux. I also grabbed a copy of Scott Granneman’s Linux Phrasebook. It’s a great book for introductory shell commands. I also have needed to consult various internet resources for some things (mainly with learning about Linux permissions).
The primary reason that I wanted an actual server in the first place (rather than stick with my previous setup of WAMPServer) was to learn more about what my hosting service deals with and to understand security risks better. In the week that I’ve had the server set up I have learned a great deal about how permissions settings on files and directories affect public access. In addition, I have learned some basic administration for vsftpd (FTP server I installed). Specifically, in editing `vsftpd.conf`, which is located at `/etc/vsftpd.conf`.