Archive

Archive for the ‘ActionScript 3’ Category

Zend Con 2009 session files

October 21st, 2009

Zend Con ‘09 has already been a great event. If your not here you need to come in 2010! Attached are the files for my Zend Amf talk on Advanced Data Communication with the Flash Platform

Session Files

Here are all the resources too!

Zend AMF Downloads
http://framework.zend.com/download/amf

Adobe Flash Builder 4 beta 2
http://labs.adobe.com/technologies/flashbuilder4/

New PHP Features in Flash Builder 4 – Part 1: Data-Centric Feature Overview
http://ria.dzone.com/articles/new-php-features-flash-builder

New PHP Features in Flash Builder 4 – Part 2: Using Zend AMF and Flash Remoting
http://ria.dzone.com/articles/new-php-features-flash-builder-2

James Ward Census
http://www.jamesward.com/blog/2007/04/30/ajax-and-flex-data-loading-benchmarks/

ActionScript 3, Flash Platform, Speaking, Zend_Amf

ArrayCollection beta update in Zend Amf: thoughts?

June 15th, 2009

I started working on a project this week that extensively uses ArrayCollection’s and I found that ZendAmf could use a couple additions in order to have some utilities for working with ArrayCollections in PHP. The new feature relies heavily on PHP’s SPL and specifically Countable, ArrayAccess, and IteratorAggregate all of which require PHP 5.2.3 or greater.

The following file can be added to your Zend Amf project to play with some of these features. Please let me know if there is anything else that I should add before it is added in the next release. Please post feedback to the blog or directly to the Zend Framework feature request.

Alpha Zend_Amf_Value_Messaging_ArrayCollection

To create an ArrayCollection

$this->_data[] = array('foo' => 'foo1', 'bar' => 'bar1');
$this->_data[] = array('foo' => 'foo2', 'bar' => 'bar2');
$this->_arrayCollection = new Zend_Amf_Value_Messaging_ArrayCollectionTwo($this->_data);

To Create an ArrayCollection from a Zend_Db_Table_row

$table = new Bugs();

$select = $table->select();
$select->where('bug_status = ?', 'NEW');

$rows = $table->fetchAll($select);
$this->_arrayCollection = new Zend_Amf_Value_Messaging_ArrayCollectionTwo($rows);

To alter an element of an ArrayCollection

$this->_arrayCollection = new Zend_Amf_Value_Messaging_ArrayCollection($this->_data);
$total = count($this->_arrayCollection);
echo($total); // outputs 2

To get the size of the array collection


to iterate through the ArrayCollection

$count = 0;
foreach($this->_arrayCollection as $row) {
    $count++;
}
$this->assertEquals(2, $count);

To manipulate an ArrayCollection based on keys.

$this->_arrayCollection = new Zend_Amf_Value_Messaging_ArrayCollection($this->_data);

// See if the offset key exists
$boolean = $this->_arrayCollection->offsetExists(1);

// Alter or add the row at they key offset of 1
$data = array('fooSet' => 'fooSet2', 'barSet' => 'barSet2');
$this->_arrayCollection->offsetSet(1,$data);

// Remove the row at the offset key of 3
$this->_arrayCollection->offsetUnset(3);

// Get the row at the offset 6
$row = $this->_arrayCollection->offsetGet(6);

To change an ArrayCollection to an Array

$standardArray = iterator_to_array($this->_arrayCollection);

To append another row to an ArrayCollection

$this->_arrayCollection->append(array('kung' => 'foo', 'Bruce' => 'Lee'));

– Update –
From a PHP developers perspective this makes little since. I am asking that you comment why you like the new ArrayCollection. I am creating something that can already be done with an array in PHP and then just wrap it into a stub ArrayCollection class. The two things that action script does not do with an array is:

it can not handle sparse array’s. {1=> one, 2=>two, 4=>four} this is a sparse array and Action Script will try and pad the array or just make it an object.

Actionscript can not use strings as the key in the array so it just uses an object. If you want a numerically keyed array of objects they call it an ArrayCollection.

Both of these concepts are handled in PHP as just an Array. So there is no reason that you could not use the Array and then pass the array into a simple ArrayCollection class for it to be parsed back to flex. So when you see the new ArrayCollection class what are the use cases that you feel you would use the class for? Is it just a convenience tool or does it add complexity that does not need to exists?

ActionScript 3, Flash Platform, Zend_Amf

Simple RemoteObject example in Flex 4 Gumbo

November 23rd, 2008

If you just received a copy of Flex 4 Gumbo like me you may have some issues getting something simple started. The following code shows how to make a simple remoteobject call inside flex builder 4. A couple gotchas that fooled me. First notice that you have to wrap your remoteobject call inside of the new declarations tag. Second you should notice that the MX namespace has been dropped for all components. This too took me a bit! 

Check out the ScreenCast and of course the code