Archive for the 'Flash' Category

Article published at TheTechLabs

Reynaldo September 3rd, 2008

Hi all:

I just got an article (first of a series) published at The Tech Labs. It basically takes you through the steps of creating and structuring classes while taking you through the basics in creating your own Web Services package with a simple Twitter API!

Have a read and lemme know what you think. Cheers!

Cannes Lions Shortlist

Reynaldo August 17th, 2008

Being eye-deep in a Papervision3D project for the last 2 months and with the arrival of our new born baby Ryan, I was totally oblivious to the fact that one of the projects I worked on earlier this year was on the Cannes Lions Titanium Shortlist! The project was dubbed “The Other You” and it was for Toyota Matrix. We basically included all types of web 2.0 technologies from extreme video production to papervision to social networks.

The whole project consisted on playing a nasty prank on a friend while you sit back and enjoy the show, very DOPE!

http://www.yourotheryou.com/

Setting up SVN on your MediaTemple Server (gs) and Accessing it with TortoiseSVN

Reynaldo August 17th, 2008

Hello fellow developers and architects!

Let me start off by saying that if you are going to use svn on your MT grid server the last place you want to go for installation instructions is the MediaTemple Knowledge Base. I can grantee you that will be cause of major hair loss on your part. Not only are the instructions vague and confusing, they’re just darn annoying.

I have absolutely no experience dealing with Linux servers or anything Linux for that matter but I was able to set up my svn repo with the help of a good friend. I figured I’d lay it out here for the world to see and not have to go through what I went through for the good part of my weekend. Enough venting, on to the good stuff!

First of all, the kb article over at MT is not completely messed up. You can actually go through steps 1-3 and still be in calm waters, but before you do that, there are a few things that I want to go over with you. First off, you need your server id; this usually starts with a letter followed by 5 numbers. You can find it in your “Service Activation Letter” email sent to you by MT when you first set hp your account under the FTP Login Information. You’re going to need the username and password too to log in to your server.

Also, in step 3 where it indicates <repo_name>, you have to replace that with the name of the repository on your server. This is not the name of your actual project. Let’s assume that you’ll name it myRepo.

Here’s the kb article, follow steps 1-3 and then come back.

Waiting…

Welcome back! At this point you should have successfully set up your svn repository on your MT grid server but we still need to add a folder for your project. Step 4 on the MT article tells you how to do that, but I found it a little confusing. So here’s a clearer explanation:

OK, so to create a folder (and sub folders) for your project we use the “mkdir” command. Let’s assume that our project name is myProject type in:

mkdir myProject
mkdir myProject/trunk
mkdir myProject/branches
mkdir myProject/tags

Now its time to import the newly created folders into the repository, remember that above we assumed that the name of our svn repository was myRepo. You’re also going to need that server id we mentioned above and replace the hashes with it. Type in:

svn import myProject file:///home/#####/data/myRepo –message “Creating initial repo.”

After pressing executing that last line you should be all set!

To access your newly created svn repo, just create a folder on your desktop (i.e.), right-click and choose “SVN Checkout”.

This is what you should put in your “URL of Repository” field; remember to change the hashes to your verver id and replace “yourdomain” with your actual domain name:

svn+ssh://serveradmin@yourdomain.com@yourdomain.com/home/#####/data/myRepo

That’s all folks! TortoiseSVN will 99.9% of the time ask you for your password. This is gonna be the same password you used on putty.

Hope this was useful!

Uploading Multiple Files : CS3 + PHP

Reynaldo August 14th, 2008

For about a week now I have been trying to upload multiple files to my server using flash and PHP. It I used the FileReference class to select the file from my system and once selected used the “upload” method to upload it and it worked like a charm! But selecting and uploading one file at a time can become pretty very annoying and tedious so I figured that using FileRegerenceList, I would be able to choose multiple files and have those upload simultaneously.

NOTE : THE FOLLOWING CODE DID NOT WORK AND I’LL EXPLAIN WHY

[source language="Ruby"]
var fileRefList:FileReferenceList = new FileReferenceList();
fileRefList.addEventListener(Event.SELECT, selectHandler);
fileRefList.browse();
function selectHandler(event:Event):void {
var request:URLRequest = new URLRequest(”http://[mydomain].com/upload.php”);
var files:FileReferenceList = FileReferenceList(event.target);
var selectedFileArray:Array = files.fileList;
for (var i:uint = 0; i < selectedFileArray.length; i++) {
var file:FileReference;
file = FileReference(selectedFileArray[i]);
file.addEventListener(Event.COMPLETE, completeHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
try {
file.upload(request);
} catch (error:Error) {
trace("Unable to upload files.");
}
}
}
function completeHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
trace(file.name+" uploaded.");
}
function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
trace("progressHandler: name = " + file.name + " bytesLoaded = " + event.bytesLoaded + " bytesTotal = " + event.bytesTotal);
}
function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}[/source]

What I was doing in the code above was using FileReferenceList to select all the files that I wanted to upload to my server, that was fine. That fires an Event.SELECT event; in the handler for that event, I created a URLRequest passing it the url to where my server side upload script is located. The FileReferenceList basically is an Array of FileReference objects, hence I figured I could loop through it, addlisteners to each of the FileReference objects, run the upload method and that's it? NOPE! Didn't work! Even though all my traces were indicating that all my files were being uploaded succesfully, when I went to check my server, there were no files there.

It turns out that flash really CANNOT UPLOAD MORE THAN ONE FILE AT A TIME.

Basically... "Listeners receive events to indicate the progress, success, or failure of the upload. Although you can use the FileReferenceList object to let users select multiple files for upload, you must upload the files one by one; to do so, iterate through the FileReferenceList.fileList array of FileReference objects.

The FileReference.upload() and FileReference.download() functions are nonblocking. These functions return after they are called, before the file transmission is complete. In addition, if the FileReference object goes out of scope, any upload or download that is not yet completed on that object is canceled upon leaving the scope. Be sure that your FileReference object remains in scope for as long as the upload or download is expected to continue.”

In other words, what i needed to do was not a run a loop, but actually create a function that will upload a single file and on the handler for the complete event for that function, load the next file in queue. Worry not if that sounds a little confusing ;) here’s the new and improved working code:

[source language="Ruby"]
var uploadQueue:Number = 0;
var selectedFileArray:Array = [];
var fileRefList:FileReferenceList = new FileReferenceList();
fileRefList.addEventListener(Event.SELECT, selectHandler);
fileRefList.browse();

function selectHandler(event:Event):void
{
var files:FileReferenceList = FileReferenceList(event.target);
selectedFileArray = files.fileList;
loadQueue(uploadQueue);
}
function loadQueue($index:Number):void
{
if($index < selectedFileArray.length){
var request:URLRequest = new URLRequest(”http://www.[mydomain].com/upload.php”);
var file:FileReference = FileReference(selectedFileArray[$index]);
file.addEventListener(Event.COMPLETE, completeHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
try
{
file.upload(request);
}
catch (error:Error)
{
trace(”Unable to upload files.”);
}
}else{
trace(”All files uploaded.”);
}
}
function completeHandler(event:Event):void
{
var file:FileReference = FileReference(event.target);
file.removeEventListener(Event.COMPLETE, completeHandler);
file.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
file.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
trace(file.name+” uploaded.”);
uploadQueue++
loadQueue(uploadQueue);
}
function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
trace(”progressHandler: name = ” + file.name + ” bytesLoaded = ” + event.bytesLoaded + ” bytesTotal = ” + event.bytesTotal);
}
function ioErrorHandler(event:IOErrorEvent):void {
trace(”ioErrorHandler: ” + event);
}[/source]

And here’s the php code that i’m using server side:

[source language="Ruby"]
//path to storage
$storage = ‘images’;

//allow path to be changed dynamically
if($_GET['uploadDir'] != “”) {
$storage = $_GET['uploadDir'];
}

//path name of file for storage
$uploadfile = “$storage/” . $_FILES['Filedata']['name'];

//if the file is moved successfully
if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( ‘1 ‘ . $_FILES['Filedata']['name']);
header(”Location: http://www.google.com”);
//file failed to move
}else{
echo( ‘0′);
}[/source]

ENJOY!

SWF embedding problem with SWFObject 2.0

Reynaldo May 26th, 2008

For the last week or so I have been having loads of issues trying to embed a swf onto an HTML page with SWFObject 2.0. It works wonders when its just a regular swf being embedded, but when the embedded swf tried loading another swf, nothing.

Now check this out, wanted to install FlashTracer so I did and I read that in order for it to work properly, I HAD to install the debug version of the Flash Player. As soon as I ran the application on the new player, I immediately got an error message:

SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file:///C:/site.swf cannot access file:///C:/index.html.

After endless hair pulling and much reading and research I found the solution to the problem. All I had to do was add the following line to my embed code on html:

so.addParam(”allowScriptAccess”,”always”);

That did the job!

Next »

  • Friends

  • Props

  • Donations

  • website counter
  • Archives

  • Feedburner