The Locked iPuzzle

So the iPad came and as expected, everyone can’t stop talking about it. I was cautiously optimistic about Apple’s tablet. I’m a sci-fi fan with a gadget fetish and I was loving the idea of carrying around a computer tablet just like they do in all of the latest science fiction movies. And Apple has a way of completely turning the computing world upside down. They have an elegance and polish that makes the intersection of software and hardware a nirvana.

Part of that is because they rule their platforms with an iron fist. The iPhone is obvious. It’s arguably the most closed platform in recent memory. Every application has to go through Apple’s approval process, can only be listed on Apple’s store, and Apple takes a cut. It’s a fantastic device, it provides developers a way to make money, but it is incredibly closed and arguably bordering on big brother. But OS X isn’t perfect either. While I can install my own applications and control my own settings, things like getting the right APIs for Flash Player to handle video or multi-touch aren’t possible.

The iPad Cometh

So when the iPad was released and it was just a bigger iPod Touch, I was incredibly disappointed. If this is the future of computing then we’ve already lost. Apple is taking total control to a new and unfortunate level. It’s the same pay-to-play model as the iPod Touch so that you’ll be buying your applications from Apple (so they can take their cut), buying your videos and music from Apple, buying your books from Apple, and dealing with their DRM for all three. The ultimate lock-in.

The Honey Trap

This is what bugs me. As an evangelist I’m annoyed Flash isn’t on the iPhone. But as a user, I’m terrified that Apple has put a vice grip on getting content on my devices. It used to be that when you bought a device, you owned it and could basically do whatever you want with it. The model of the iPad and the iPhone is the opposite of that. You’re essentially paying for a device that then gives you the privilege to buy content from Apple. The honey pot of a seamless software-hardware experience has become a nightmarish trap that keeps you stuck and struggling.

As Mike Chambers said better than I can, having some support for HTML5 in Safari doesn’t make an open platform. One of the great parts of the “open web” is exactly how open it is. Anyone can put up any piece of content, at any time, without asking for permission. The web is accepting of Flash content, HTML content, Silverlight content, numerous video and audio codecs, and other plug-ins. Users have the ultimate choice about what they want to see and how they want to see it. That ecosystem has led to a lot of great, free content like games, video, and applications.

Which is why Apple has locked down the device. They can’t make money off of free. And instead of giving users choice and opening up their devices, they’ve decided to lock it down. The iPhone and iPad are each great pieces of technology and Apple deserves to make money off of them. But they could be so much better if they were open. The number of innovative things that an open ecosystem could do with this technology is mind-boggling. But that won’t happen because the only ideas that will see the light of day are ideas Apple lets through.

We’ve come a long way from 1984, but obviously not long enough.

On Google, YouTube, HTML5, Adobe, and Flash

Last night Google blogged about how they were experimenting with offering some videos on YouTube that support the HTML5 video tag and the H.264 codec, and that work in Chrome and Safari. This is part of TestTube, where YouTube’s engineers test out different products without rolling them into the main YouTube experience. YouTube and Flash obviously have a deep relationship. It was Flash that helped YouTube become one of the most visited sites on the Internet, and YouTube has helped increase penetration of newer versions of Flash Player by rolling out features, like H.264 support, that required the newer Flash Player versions.

There is always an undercurrent questioning if Flash is “going away” when it comes to HTML5. But I think YouTube is actually the perfect example of Flash and HTML working together. The same day Google blogged about the TestTube project, YouTube also rolled out a new rental service for some of the Sundance Film Festival videos, which is powered by Flash. And I think that shows the relationship that Flash and services like YouTube have in helping drive the web forward.

Video on the web isn’t just about watching a clip any more. There are ways to monetize it, either with advertising or by adding ways to protect content that lets people watch something after they pay. There are accessibility issues that need to be addressed like closed-captioning support. What about being able to consume video on mobile devices that don’t support the HTML5 video tag? These are all areas that Flash has found solutions to, which has helped the growth of video on the web and provided a reference for the HTML5 groups to see what works. And while there may be some arguments over the use of the H.264 codec, having Flash add support for that codec meant that companies like Google could roll out a Flash version and an HTML5 version without having to re-encode video. Flash has made possible many of the features in HTML5 by showing how good the experience can be. And Flash will continue to innovate and provide solutions to challenges on the web before those solutions can be standardized. It will remain the best way to provide cutting-edge technology to 98% of people online.

Open standards are incredibly important to the future of the web. Adobe continues to work hard to contribute to that movement and balance that with the need for our customers and developers to be able to create next-generation content that runs the same way on every operating system and device. If Flash wasn’t providing value to people, it wouldn’t be on 98% of the world’s computers and we wouldn’t see penetration for new versions reach 80% within 6 months of release.

So congrats to YouTube on the HTML5 video work. This is good for HTML and I think there will be a lot of Adobe, Flash, and HTML5 collaboration moving forward. Flash has an important role to play by providing innovative ideas and solutions for an increasingly multi-screen and multi-platform world.

What’s Up With All the PHP? Or My New(ish) Role at Adobe

I’ve been blogging more recently about PHP, which may be confusing for people who know me and my ColdFusion background. But in looking at things, the PHP community has been incredibly vibrant and successful on a number of fronts. We’ve started adding more support for PHP developers through partnerships and support of things like Zend AMF, the PHP Data Wizards in Flex Builder, and encouraging community speakers at events like ZendCon. On the Adobe side, Mihai Corlan has done a fantastic job of creating resources for PHP developers who want to learn Flex. The team needed someone to take the lead here in North America and I asked to do it (Lee is busy with cool Flash stuff and going to Latin and South America). So now PHP developers have a go-to guy here in North America working to further the PHP agenda here at Adobe and helping more PHP developers be successful with Flex and Flash.

So why me, someone with little PHP experience? I’ve always felt like evangelism is about growing your developer community and developer relations is about helping the community you have. At Adobe we don’t really have a specific developer relations role (it’s basically Mike Chambers) so the evangelists end up doing both. Which is fun because our community is awesome. But I also wanted a challenge and to grow professionally as an evangelist. I thought the best way to do that would be to get out of my comfort zone, immerse myself in a new technology, and execute on ideas that could be applied to any technology by any evangelist.

Luckily we’re working with some great PHP people and the PHP community is a very welcoming and open place. There are a lot of places where PHP and Flash fit really well together so there are features like data visualization, collaboration, video, and data-heavy applications where I think PHP developers can use Flash in a helpful way. And in the process hopefully I’ll end up being a better evangelist and helping to grow the number of Flex developers.

If you’ve got ideas, or applications that show off Flash and PHP together, I’d love to hear them. You can always drop me an email at ryan@adobe.com or call/text me at (307) 438-9716. I think 2010 is going to be a huge year for PHP and Flash momentum.

New Zend AMF with 10x Performance Boost

Wade just blogged about a patch that was submitted by Mark Reidenbach to Zend AMF that provides a 10x performance boost over the old one. This isn’t a final release and everyone is still making sure the patch hasn’t introduced any new bugs so he’s encouraging everyone to download this one and make sure it works correctly. If you have issues, add it to the current open bug.

From Wade’s post:

Thanks so much Mark! I have also added a reference check optimization that uses SPL_object_hash to quickly see if an object has been seen before or not. Overall you should see a big performance increase. The test case I used was the James Ward’s census data from my ZendCon talk which consists of random people objects ranging from 1 – 100 duplicates totaling 5k total rows. Xdebug profiling analyzed by KCacheGrind showed roughly a 10X increase in performance!

Mapping Data Types from PHP to Flex with Zend AMF and Flash Builder 4

I assume this has to be out there somewhere but I couldn’t find it so hopefully this helps someone who Google’s things the same way I do. And Wade has a great tutorial for doing this when you’re just dealing with the Zend AMF code but I was looking for something that worked with Flash Buidler 4′s wizards.

While using the Flash Builder 4 data-centric design wizards to generate the service calls for a PHP class I was having trouble figuring out how to make sure that the data types I had set up in my MySQL database were being carried all the way through to my Flex application. When I retrieved data from the database in PHP and then had Flash Builder 4 inspect my class, the properties of my returned class were all strings.

If you use the data-centric design wizards to create a class based on a database, the class properties are typed correctly. If you use a class you’ve already written, all of the properties come back as strings. Luckily I chatted with our Flex/PHP guru, Mihai Corlan, and he pointed me in the direction of type casting.

Essentially you just need to add a bit of extra data when the properties are returned in the class so that Zend AMF knows what type of data to expect. So for my getAllItems() method, I iterate through the records of my database and create a PHP object for each one.

As you can see in the code below, to return as an int, just add a 0; to set it as a number, add 0.0; to set it as a date, just create a new DateTime object with the data from MySQL. As you can see from the Mapping Table you’ve got coverage for pretty much every data type.

public function getAllForests()
{
     $this->connect();
     $rs = mysql_query("select * from national_forests")
          or die ("Unable to complete query.");
 
     $national_forests = array();
 
     while( $row = mysql_fetch_assoc($rs) )
     {
          $forest = new NationalForest();
          $forest->id = $row['id']+0;
          $forest->state = $row['state'];
          $forest->area = $row['area']+0.0;
          $forest->established = new DateTime($row['established']);
          $forest->closest_city = $row['closest_city'];
          $forest->name = $row['name'];
 
          array_push($national_forests,$forest);
     }
 
     return $national_forests;
}

If there’s a better way to do this, I’d love to have it.

Register for 360|Flex and Be the First to Win Uber CS Next

Are you planning on going to 360|Flex San Jose March 7-10th? Have you registered yet? If not I’ve got a deal for you. I’m going to be giving away a copy of whatever the highest suite level is for the next version of Creative Suite to a random attendee who registers on the 360Flex site with my URL which is http://360flex-rfs.eventbrite.com/. Here’s how it will work. I’ll randomly select one person from the list of people who register with that URL. If you’re the winner I’ll email you to find out if you want Mac or Windows. Then, if CS Next is released before 360Flex, I’ll bring you a copy to take home. If it’s released afterwards I’ll take your address and send it to you.

I’m also going to be holding a contest for the designer-types which I’ll announce later when I nail down the specifics. But hopefully this gives you all a jolt to register for 360Flex sooner rather than later.

In-Game Payments with Flash and Social Gold

Gaming is obviously a huge part of the Flash marketplace and luckily this year we as a company have started to acknowledge that and hopefully address developer needs. Part of that was the Flash CS5 support for creating iPhone applications. Another is the “Shibuya” try/buy service that we have, which allows developers to much more easily monetize their AIR applications (and thus AIR-based Flash games). But the coolest thing is seeing the ecosystem grow up around this. A great example is Social Gold.

Social Gold takes the monetization of Flash content to the next level by allowing users to make in-game purchases. They’ve got an API that lets you do everything from micropayments to recurring subscriptions. They’ve got a good demo of the workflow on their site. They handle all of the credit card processing so it’s relatively straightforward to include the Flash code in your application and start accepting payments. The revenue split is about 90-10, which seems very fair.

All of the samples are for games, but there’s nothing to prevent this from going in any other type of Flash application, so it’s a very interesting way to monetize Flash content in the browser or on the desktop with AIR. One of the main issues is security. Because SWF files can be decompiled, there’s the potential for problems if you try to embed secret keys inside of your Flash application. This can lead to a spoofing attack where a malicious SWF file gets your information and authenticates against Social Gold’s system. Social Gold attempts to solve this by keeping the keys on the server only and just passing session variables back and forth. I’m not a security guy, so I won’t comment on the implementation, but it seems like a reasonable approach considering the security constraints of Flash.

We saw with the iPhone how important it is for developers to monetize content and so it’s great to see more opportunities to do that come to the Flash Platform. I think 2010 is going to be a big year for small Flash shops or individual developers who want the freedom of making a living on the Platform.

Flex and PHP: Authentication With an HTML Login Page

One of the first things to think about when building a Flex application is how you’re going to do authentication. Most people seem to include a username and password box in Flex and then make an HTTPService or AMF call to pass the authentication credentials. But I hate that solution. Most major browsers now have support to save usernames and passwords with autocomplete and that’s become something people expect from their logins. I think it’s also important to be able to clear the “remember me” cookie just like any other cookie as opposed to having it saved in a Flash cookie. Whenever you can provide the behavior people expect from their browser, you should.

So in this example I’m going to show how you might implement an HTML form with PHP for a Flex application. As I’m new to PHP there may be some bad practices here but I’ll update the post as I get feedback.

Creating the login page in PHP and HTML

To start, we can just use PHP’s built in session functions to create the session variables and build the login page called login.php. You start off by creating a session with session_start() and then you set some session variables to their defaults. Then you’ll show the username and password fields only if the form hasn’t been submitted and use the $_SESSION variables to store the information from the user. Finally, when everything is authenticated you use the header() function to send the user to the Flex application.

<?php
session_start();
$_SESSION['logged_in'] = false;
$_SESSION['username'] = "";
 
if(isset($_POST['is_submitted']))
{
$username = $_POST['username'];
$password = $_POST['password'];
 
// If the "Remember my username" box is checked
// then we use the setcookie function to save it.
// Otherwise, we clear it out. 
if($_POST['keep_username'] == true)
     {
          setcookie("username",$username,time()+36000);
     } else {
          setcookie("username");
     }
 
// This is where you would look up the username
// and password. Normally this would be an LDAP call
// or a query to a database. In this case, I'm just
// accepting everything.
if($username && $password)
     {
// Set our session variables.
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $username;
 
// Redirect to the Flex application
          header("location:flex/index.php");
     } else
{
echo "Go back and put in a username and password.";
     }
} else {
?>
 
<form name="login" action="<?php$_SERVER['PHP_SELF'] ?>" method="post">
     Username: <input type="text" name="username" value="<?php echo $_COOKIE['username']; ?>" /><br/>
     Password: <input type="password" name="password" /><br/>
     Remember my username: <input type="checkbox" name="keep_username" value="true"><br/>
<input type="hidden" name="is_submitted" value="true" />
<input type="submit" value="Submit" />
</form>
 
<?php 
}
?>

Notice the keep_username checkbox above. If the user checks that, you use the setcookie() method to create a cookie that will store the username on the next visit. If it is unchecked, the username will be blank.

Setting up the Flex Project

Even though most Flex applications take up the entire page, nearly all of the time you embed the actual SWF file on an HTML page. In Flash Builder when you create a new Flex application in creates the SWF files and the HTML files for you that embed your application. To do that it uses a template file that you can find in the html-template folder of your project. If you haven’t done so yet, go ahead and create a new Flex project. Use the defaults (do not use PHP as the server, leave it at None/Other). When you get to the second screen, set the output folder to a subdirectory named “flex” in the directory where your login.php file is located.

With the project created the first thing you’ll want to do is edit the template file. Go into the html-template directory and rename index.template.html to index.template.php. That will let you run PHP code inside of the template file. Flash Builder will automatically create an index.php file in the flex folder you specified in the create project wizard. Next you need to make sure your application will use the right file when you run or debug it. Right click on your project, select properties, and then select Run/Debug Settings. Now select your project in that box and click the “Edit” button. On the next screen, uncheck “Use default” in the lowest box and type the path to your application. You can see mine below (I’ve got http://localhost:8888 mapped to http://rainier.cascade.mtn but your local PHP server will probably use http://localhost).

Modifying the Index Template

Next you need to edit the template you just renamed. Open it up in Flash Builder (or your favorite text editor) and you should see a bunch of HTML. At the very top of that page you’re going to add some PHP code. First, you are going to check for a url parameter named logout to be passed. If it is, you destroy the session and log the user out. If that isn’t passed, you’re going to use the session information from your login page and save that information to variables on this page. This code goes at the very top before all of the HTML in your template page.

<?php     
// Always start the session first.
     session_start();
 
     // You will also use this page to log out. If 
     // ?logout=1 is passed in the URL, destroy the 
     // session and log the user out.
     if(isset($_GET['logout']))
     {
          if($_GET['logout'] == 1)
          {
              $params = session_get_cookie_params();
              setcookie(session_name(),"", time()-3600,
                  $params["path"], $params["domain"],
                  $params["secure"], $params["httponly"]);
               session_unset();
               session_destroy();
          }
     }
 
     // Create the default values for our session.    
     $session_id = "";
     $logged_in = false;
     $username = "";
 
     // If the session is valid, replace the default
     // values with our session values.
     if($_SESSION['logged_in'] == true)
     {
          $logged_in = true;
          $session_id = $_COOKIE['PHPSESSID'];
          $username = $_SESSION['username'];
?>

Now that your variables are set, you’ll send those to Flash Player. There are a number of ways to get data into your Flex application but the most straightforward is to use a concept referred to as “flashvars”. Flashvars are parameters you can put within the embed code that will then be accessible by the Flex application. Flashvars are a great way to take a dynamic site, like one written in PHP, and change the behavior of a Flex or Flash application based on that dynamic PHP data. Look for the JavaScript in the template that includes var flashvars = {} and replace it with this code.

var flashvars = {session_id:"<?php echo $session_id; ?>",               
logged_in:"<?php echo $logged_in; ?>",
username:"<?php echo $username; ?>"};

That code will make those three variables available to your Flex application. That way before you let the user do anything in your Flex application you can check to make sure the user is logged in correctly.

Finally, at the end of the template you’ll add some code to show the user an error message if they try to access the page without logging in.

<?php              
} else {
     echo "Not authorized, go back and log in.";
}
?>

Creating the Flex Application

In this example you’ll just create a very, very basic Flex application with two states, a beginning state and a logged in state. When the application loads, check the flashvars you added to the embed code and then change to the logged in state. The logged in state also contains a button that uses the logout functionality you added to the template code. Here’s the whole Flex application.

<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                  xmlns:s="library://ns.adobe.com/flex/spark" 
                  xmlns:mx="library://ns.adobe.com/flex/mx" 
                  minWidth="955" minHeight="600" currentState="startingScreen"
                  creationComplete="application1_creationCompleteHandler(event)">
 
<fx:Script>
     <![CDATA[
          import mx.controls.Alert;
          import mx.events.FlexEvent;
          import mx.utils.ObjectUtil;
 
          protected function btn_clickHandler(event:MouseEvent):void
          {
               navigateToURL( new URLRequest( encodeURI("index.php?logout=1")), "_self");
          }
 
          protected function application1_creationCompleteHandler(event:FlexEvent):void
          {
               if(this.parameters.logged_in == 1)
               {
                    currentState = 'loggedIn';
               }
          }
 
     ]]>
</fx:Script>
 
<fx:Declarations>
     <s:State name="startingScreen" />
     <s:State name="loggedIn" />
</fx:Declarations>
 
     <s:Panel name="Test" left="25" right="25" top="20" 
               bottom="25" title="My Application">
          <s:Button id="btn" left="10" top="10" 
                    click="btn_clickHandler(event)" 
                    label="Log Out" includeIn="loggedIn" />
          <s:Label id="lbl" left="10" top="10" 
                    text="You need to log in" 
                    includeIn="startingScreen" />
     </s:Panel>
 
</s:Application>

Conclusion and Warnings

There are a couple of notes and warnings about this method. By using two states and checking the login parameters you aren’t just depending on the embed code. That means if someone browses right to the SWF file they won’t be able to access the application because it won’t move to the next state unless it gets those parameters. That’s also part of the problem in this very simple application.

In the Flex code that changes the state I just check to see if the flashvar logged_in is set to 1. If you were to download a local version of the PHP file as well as the SWF and change that embed code you’d have access to the application. In a more robust example you would want to add a couple of hooks into the database. One way to do that would be to store the session id and the username in the database in the login.php file. Then when your Flex application loaded you could make a call to another PHP page and pass the session id and username parameters to a function which would compare it to the session and username that were stored during login to make sure it matches up.

You might also want to implement a token system with a shared secret which is a good way to authenticate against external APIs, the kind that you would create in PHP and consume in a Flex application using AMF or REST.

So keep in mind that this isn’t ready for production. But hopefully it gets you started in the right direction when creating a PHP/Flex application that is going to use an HTML login form. The fewer Flex/Flash login forms there are the better. Update: I’ve added a GitHub repository with the code. I’m hoping to add to this as I fill in some of the gaps that I warned about above.

Flash Camp Phoenix – January 29th

If you’re in the Phoenix area and are interested in hearing from some great speakers talk about Flex, Flash, and AIR, you’ll want to check out Flash Camp Phoenix on January 29th. I love coming down to Phoenix because it’s a great community. And there’s a lot to talk about. We’ve started releasing more info on Flash Player 10.1 for mobile devices, we’ve had AIR 2 in public beta for a while, and our Flash Platform family of tools is starting to come together in a big way.

I may also try to set up some hiking afterwards with Dan Florio so if you’re interested, keep that in mind.

Flash Player 10.1 and Palm’s App Catalog

Palm made a bunch of announcements today about new products, their development program, and an app catalog. Palm was an early supporter of the Flash Platform on devices and member of the Open Screen Project so I was glad to see this tidbit in their press release:

Palm also demonstrated Flash content in the browser on a Palm Pre and expects a free Adobe Flash Player 10.1 plug-in to be posted to the Palm App Catalog in the coming months. Palm expects webOS to be one of the first mobile platforms to support the full Flash Player in the web browser.

That should mean that it will run on the Palm Pre as well as the new devices announced. Adrian did a demo of Flash Player 10.1 in action on the Palm Pre recently and you can check out the embedded video below.