2007. szeptember 27., csütörtök

Using the flash.* classes in MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/26/using-the-flash-classes-in-mxml/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flash.filters="flash.filters.*"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">

<mx:Array id="filterArray">
<flash.filters:DropShadowFilter id="dropShadowFilter"
angle="90"
blurX="5"
blurY="5"
distance="2"
alpha="0.9"
color="0xFF0000" />
<flash.filters:BlurFilter id="blurFilter"
blurX="3"
blurY="3"
quality="3" />
</mx:Array>

<mx:Label text="{flash.system.Capabilities.version}"
fontSize="32"
filters="{filterArray}" />

</mx:Application>


http://blog.flexexamples.com/

2007. szeptember 21., péntek

list-at-a-time in as3

package
{
import fl.controls.List;
import fl.data.DataProvider;
import flash.display.MovieClip;
public class ArrayFilterTest extends MovieClip
{

protected var original_ar:Array
protected var filtered_ar:Array
protected var mapped_ar:Array

public function ArrayFilterTest()
{
trace( "[ArrayFilterTest] - ArrayFilterTest() :: Constructed." )

original_ar = new Array()
filtered_ar = new Array()
mapped_ar = new Array()

for( var i:uint = 0; i < 10; i ++ )
{
original_ar.push( new ArrayTestItem() )
}

trace( "[ArrayFilterTest] - ArrayFilterTest() :: Original array: " )
original_ar.forEach( traceItem )

trace( "[ArrayFilterTest] - ArrayFilterTest() :: Filtered array: " )
filtered_ar = original_ar.filter( filterItems )
filtered_ar.forEach( traceItem )

trace( "[ArrayFilterTest] - ArrayFilterTest() :: Mapped array: " )
mapped_ar = original_ar.map( mapItems )
mapped_ar.forEach( traceItem )
}

private function traceItem( element:ArrayTestItem, index:int, arr:Array ):void
{
trace( index + "\t\t" + element.ID + "\t\t" + element.test )
}

private function filterItems( element:ArrayTestItem, index:int, arr:Array ):Boolean
{
return element.test
}

private function mapItems( element:ArrayTestItem, index:int, Array:Array ):ArrayTestItem
{
var e:ArrayTestItem = new ArrayTestItem()
e.ID = element.ID
e.test = false
return e
}
}
}

class ArrayTestItem
{

public var test:Boolean
public var ID:Number
public function ArrayTestItem()
{
test = Math.random() > 0.5
ID = Math.floor( Math.random() * 1000 )
}
}


http://eokyere.blogspot.com/

2007. szeptember 20., csütörtök

Converting XML to objects using the Flex HTTPService MXML tag

"... The following example shows how you can convert an XML file loaded at run-time using the HTTPService tag, into an ActionScript Object by simply setting the resultFormat property to “object”."

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservice-mxml-tag/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="serv.send();">

<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

private function serv_result(evt:ResultEvent):void {
var resultObj:Object = evt.result;
/* Assign the values... */
nameText.text = resultObj.album.name;
img0Text.text = resultObj.album.images.image[0];
img1Text.text = resultObj.album.images.image[1];
img2Text.text = resultObj.album.images.image[2];
}

private function serv_fault(evt:FaultEvent):void {
/* Show the error label. */
error.text += evt.fault.faultString;
error.visible = true;
/* Hide the form. */
form.visible = false;
}
]]>
</mx:Script>

<mx:String id="XML_URL">album.xml</mx:String>

<mx:HTTPService id="serv"
url="{XML_URL}"
resultFormat="object"
result="serv_result(event);"
fault="serv_fault(event);" />

<mx:ApplicationControlBar dock="true">
<mx:Label text="{XML_URL}" />
</mx:ApplicationControlBar>

<mx:Label id="error"
color="red"
fontSize="36"
fontWeight="bold"
visible="false"
includeInLayout="{error.visible}"/>

<mx:Form id="form"
includeInLayout="{form.visible}">
<mx:FormItem label="resultObj.album.name:">
<mx:Label id="nameText" />
</mx:FormItem>
<mx:FormItem label="resultObj.album.images.image[0]:">
<mx:Label id="img0Text" />
</mx:FormItem>
<mx:FormItem label="resultObj.album.images.image[1]:">
<mx:Label id="img1Text" />
</mx:FormItem>
<mx:FormItem label="resultObj.album.images.image[2]:">
<mx:Label id="img2Text" />
</mx:FormItem>
</mx:Form>

</mx:Application>


<?xml version="1.0" encoding="utf-8"?>
<album>
<name>One</name>
<images>
<image>image1.jpg</image>
<image>image2.jpg</image>
<image>image3.jpg</image>
</images>
</album>


http://blog.flexexamples.com

2007. szeptember 19., szerda

ToolTips for ComboBox Items or List Items

"... I initially thought this should be possible by setting the showDatatips and the dataTipField on the List, but it didn’t work as expected for me."

private var myDropdownFactory:ClassFactory;

private function initApp():void
{
myDropdownFactory = new ClassFactory( List );
myDropdownFactory.properties = { showDataTips:true, dataTipFunction:myDataTipFunction }
}

private function myDataTipFunction( value:Object ):String
{
return ( value.name + "’s blog is " + value.blog );
}


<mx:ComboBox id="myCB" dataProvider="{ myDP }" labelField= name" dropdownFactory="{ myDropdownFactory }" />


http://raghuonflex.wordpress.com/

2007. szeptember 17., hétfő

Your Tweens aren’t finishing.

"Or your URLLoaders won’t load. Or your Timers stop ticking.

function doStuff():void
{
var x:Object = {};
}


When this method is called, it creates an object and stores a reference to it in the variable x. After the function finishes executing, there are no remaining references to the object, so the Flash Player clears it from memory (as soon as it gets around to it). Of course, this happens no matter what type of object we create.

Unfortunately, there are some situations where this behavior can cause major problems. Objects like Tween, Loader, and Timer are associated with asynchronous processes (animating, loading, etc..) that we expect to complete regardless of whether the objects that originated them are still in the player’s memory. "


http://exanimo.com/actionscript/never-use-tween-or-urlloader/

2007. szeptember 13., csütörtök

Building monolithic Flex SWFs that still startup quickly

"...First, I created a simple plain Flex 2 Application. Next, a class called TestFactory which implements mx.core.IFlexModuleFactory was created. This class will later be used to create instances of a Module called Test. The TestFactory class also implements a public static function frame(value:Object):void which is needed later.

To link the TestFactory class onto an additional frame "outside" the default 2 frame section you'll have to add something like

  -frame test TestFactory 


to the mxmlc arguments (either in Flex Builder or on the command line). This creates the 3 frame SWF file.

At runtime when frame 3 is hit, the static frame() method on the TestFactory class is called (this is not documented anywhere) passing in an instance of the active SystemManager implementation. Inside this method you can then register the TestFactory on the ModuleManager:

ModuleManager.getModule("published://myTest").publish(new TestFactory());


Note: Although in the documentation it says to use an URL starting with publish:// it actually has to be published://. After the Module is published you can call

ModuleManager.getModule("published://myTest");


from withinh the application to get a reference to the TestFactory instance and call create() on it to create an instance of whatever is created by the factory class."

http://www.richinternet.de/blog/

How to load external assets from an AS3 file using the Flex SDK

Resource.as:

package
{
import flash.display.Sprite;

// This _must_ inherit from Sprite, or the resources can't be attached to
// the main movie.
public class Resources extends Sprite
{
// List your resources here, as public variables
[Embed(source="mysource.swf",symbol="AnySymbol")]
public var SomeSymbol:Class;
}
}


compile:

mxmlc Resources.as -output resources.swf -sp . -no-network=false


"...load it into your app using a standard flash.display.Loader, without specifying an applicationDomain. Once loaded, get at the assets like this:"

var ResourceClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("Resources") as Class;
var resources:Object = new ResourceClass();
var symClass:Class = resources['SomeSymbol'] as Class;
var symbol:MovieClip = new symClass() as MovieClip;


http://wildwinter.blogspot.com/

Making it official: the next major release of Flash Player is codenamed "Astro"

Emmy Huang
Product Manager for Adobe Flash Player

http://weblogs.macromedia.com/emmy


... it's time to start focusing on life after "Moviestar," and we have more bunnies to pull out of our hats.

ActionScript 3.0 - using variables in XML

package {

import flash.display.Sprite;

public class XMLExample extends Sprite {

private var someXML:XML;
private var myName:String = "Peter";
private var myEmail:String = "info at peterelst dot com";

public function XMLExample() {
someXML =
<friends>
<person name={myName}>
<email>{myEmail}</email>
</person>
</friends>;

trace(someXML.toString());
}

}
}


http://www.peterelst.com/