A következő címkéjű bejegyzések mutatása: as3. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: as3. Összes bejegyzés megjelenítése

2007. október 29., hétfő

Resumable Downloads with AIR

Here is how a sample Request looks like:
GET /files/richflv/help/ExportOptions.flv HTTP/1.1
Referer: app-resource:/LoadingTest.swf
x-flash-version: 9,0,60,153
Range: bytes=1200000-1300000
User-Agent: Mozilla/5.0 (Windows; U; en) AppleWebKit/420+ (KHTML, like Gecko) AdobeAIR/1.0
Host: www.richapps.de

In Actionscript we can write a custom header like this:
var header1:URLRequestHeader = new URLRequestHeader("range","bytes="+currentBytesPosition+"-"+toRange);
var re:URLRequest = new URLRequest(downLoadURL);
re.requestHeaders.push(header1);
currentBytesPosition = toRange;
urlStream.load(re);

http://www.richapps.de/?p=113

Async APIs and Callback Functions

"Making the FileStream a member variable is also essential. If the FileStream were instead declared inside someFunction(), it would go out of scope when someFunction() returned and could be garbage collected before the file is read or events are delivered. Many people are surprised by this, but note that the only reference to the FileStream object is the member variable. The FileStream object has references on event listeners, etc. but only references to an object will protect it from collection."

Now, this will almost never happen to you because (a) the garbage collector runs incrementally and it'll take it a while to collect the FileStream object and (b) most file reads will finish and dispatch a complete event long before then. But it can happen, which of course means it'll probably only show up when doing big important demos.

http://blogs.adobe.com/simplicity

"It turns out I was incorrect about this and that some related objects, such as URLStream, are guaranteed to remain live until after they have dispatched a completion event. This behavior is both more useful and more intuitive; after all, it only makes sense that there would be a reference to the URLStream somewhere in the system while it's hanging around receiving data."

http://blogs.adobe.com/simplicity

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 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

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/