Skip to Content
Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime
book

Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime

by Rich Tretola
April 2008
Beginner
350 pages
8h 21m
English
Wrox
Content preview from Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime

B.3. Chapter 8 Exercise

This exercise asked you to create a new file and set its contents to a specific string. To do this, you will need to use both the File class for creating the file and the FileStream class to write out the contents of the file. If you look at Listing B-3, you will see that there is a single function named createFile(). This function first uses the File class to create a file named Today.txt on the desktop. It then creates the string in a variable named s, which was requested per the instructions by using the Date class to capture today's date. Finally, using the FileStream class, the new file is opened in Write mode, and the contents of the s variable are written to the file. The results can be seen in Figures B-3 and B-4.

Example B-3. The solution for the Chapter 8 Exercise
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
<!--
    Create a new file on the desktop named Today.txt and set its contents to
    be "Today is (insert the date using the Date class) and I have
    created my first file from AIR."
    -->
    <mx:Script>
        <![CDATA[
        import mx.controls.Alert;
        private function createFile():void{
            var newFile:File = File.desktopDirectory.resolvePath("Today.txt");
            var d:Date = new Date();
            var s:String = "Today is " + d + "" +
                           " and I have created my first file from AIR.";
            var fileStream:FileStream = new FileStream(); fileStream.open(newFile, FileMode.WRITE); fileStream.writeUTFBytes(s); fileStream.close(); mx.controls.Alert.show( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Adobe Flex 2: Training from the Source

Adobe Flex 2: Training from the Source

Jeff Tapper, James Talbot, Matt Boles, Ben Elmore, Mike Labriola
Flash Out of the Box

Flash Out of the Box

Robert Hoekman Jr.
JavaFX™: Developing Rich Internet Applications

JavaFX™: Developing Rich Internet Applications

Jim Clarke, Jim Connors, Eric Bruno

Publisher Resources

ISBN: 9780470229040Purchase book