19.11.2012 Views

Building Adobe AIR Applications

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CREACIÓN DE APLICACIONES DE ADOBE <strong>AIR</strong><br />

Actualización de aplicaciones de <strong>AIR</strong><br />

} else {<br />

saveFile();<br />

}<br />

log.text += "Welcome to the application.";<br />

}<br />

private function firstRun():void {<br />

log.text = "Thank you for installing the application. \n"<br />

+ "This is the first time you have run it.";<br />

saveFile();<br />

}<br />

private function saveFile():void {<br />

var stream:FileStream = new FileStream();<br />

stream.open(file, FileMode.WRITE);<br />

stream.writeUTFBytes(currentVersion);<br />

stream.close();<br />

}<br />

]]><br />

<br />

<br />

<br />

Este concepto se muestra en el siguiente ejemplo de JavaScript:<br />

<br />

<br />

<br />

<br />

var file;<br />

var currentVersion = "1.2";<br />

function system extension() {<br />

file = air.File.appStorageDirectory.resolvePath("Preferences/version.txt");<br />

air.trace(file.nativePath);<br />

if(file.exists) {<br />

checkVersion();<br />

} else {<br />

firstRun();<br />

}<br />

}<br />

function checkVersion() {<br />

var stream = new air.FileStream();<br />

stream.open(file, air.FileMode.READ);<br />

var reversion = stream.readUTFBytes(stream.bytesAvailable);<br />

stream.close();<br />

if (reversion != currentVersion) {<br />

window.document.getElementById("log").innerHTML<br />

= "You have updated to version " + currentVersion + ".\n";<br />

} else {<br />

saveFile();<br />

}<br />

window.document.getElementById("log").innerHTML<br />

+= "Welcome to the application.";<br />

Última modificación 30/10/2012<br />

266

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

Saved successfully!

Ooh no, something went wrong!