15.10.2012 Views

Actionscript 3 Entwicklerhandbuch

Actionscript 3 Entwicklerhandbuch

Actionscript 3 Entwicklerhandbuch

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ACTIONSCRIPT 3.0 ENTWICKLERHANDBUCH<br />

Ziehen und Ablegen in AIR<br />

Verwenden eines synchronen Datenprovider in einer Dateizusage<br />

Adobe AIR 2 und höher<br />

Die einfachste Methode zur Implementierung der IFilePromise-Schnittstelle ist die Verwendung eines synchronen<br />

Datenprovider-Objekts, wie ein ByteArray-Objekt oder ein synchrones FileStream-Objekt. Im folgenden Beispiel wird<br />

ein ByteArray-Objekt erstellt, mit Daten gefüllt und dann beim Aufruf der open()-Methode zurückgegeben.<br />

package<br />

{<br />

import flash.desktop.IFilePromise;<br />

import flash.events.ErrorEvent;<br />

import flash.utils.ByteArray;<br />

import flash.utils.IDataInput;<br />

}<br />

public class SynchronousFilePromise implements IFilePromise<br />

{<br />

private const fileSize:int = 5000; //size of file data<br />

private var filePath:String = "SynchronousFile.txt";<br />

}<br />

public function get relativePath():String<br />

{<br />

return filePath;<br />

}<br />

public function get isAsync():Boolean<br />

{<br />

return false;<br />

}<br />

public function open():IDataInput<br />

{<br />

var fileContents:ByteArray = new ByteArray();<br />

}<br />

//Create some arbitrary data for the file<br />

for( var i:int = 0; i < fileSize; i++ )<br />

{<br />

fileContents.writeUTFBytes( 'S' );<br />

}<br />

//Important: the ByteArray is read from the current position<br />

fileContents.position = 0;<br />

return fileContents;<br />

public function close():void<br />

{<br />

//Nothing needs to be closed in this case.<br />

}<br />

public function reportError(e:ErrorEvent):void<br />

{<br />

trace("Something went wrong: " + e.errorID + " - " + e.type + ", " + e.text );<br />

}<br />

Letzte Aktualisierung 27.6.2012<br />

665

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!