Commit b030b3f0 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+26 −0
Changes for 9780596522506-code_excerpts/ch01.txt: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
chapter: AIR Basics
==================
1.7.1

var myFile:File = File.documentsDirectory.resolvePath("textFile.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(myFile, FileMode.READ);
var fileData:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
fileStream.close();
    
    
====================================
1.7.2

var myFile:File = File.documentsDirectory.resolvePath("textFile.txt");
var fileStream:FileStream = new FileStream();
fileStream.addEventListener(Event.COMPLETE,handleComplete);
fileStream.openAsync(myFile,FileMode.READ);

function handleComplete(event:Event):void {
    var data:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
    fileStream.close();
}
    
    
==================
 No newline at end of file
+392 −0
Changes for 9780596522506-code_excerpts/ch02.txt: 392 added lines, 0 removed lines.
Original line number Diff line number Diff line
chapter: Application Settings
==================
2.1.1

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.5">
...
</application>
    
    
====================================
2.2.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    ...

</application>
    
    
====================================
2.3.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    ...

</application>
    
    
====================================
2.4.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    ...

</application>
    
    
====================================
2.5.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    ...

</application>
    
    
====================================
2.6.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

</application>
    
    
====================================
2.7.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

  <installFolder>OReilly</installFolder>

</application>
    
    
====================================
2.8.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

  <installFolder>OReilly</installFolder>
  <programMenuFolder>AIR Cookbook</programMenuFolder>

</application>
    
    
====================================
2.9.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

  <installFolder>OReilly</installFolder>
  <programMenuFolder>AIR Cookbook</programMenuFolder>

  <icon>
    <image16x16>icon/icon-16.png</image16x16>
    <image32x32>icon/icon-32.png</image32x32>
    <image48x48>icon/icon-48.png</image48x48>
    <image128x128>icon/icon-128.png</image128x128>
  </icon>

</application>
    
    
====================================
2.10.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

  <installFolder>OReilly</installFolder>
  <programMenuFolder>AIR Cookbook</programMenuFolder>

  <icon>
    <image16x16>icon/icon-16.png</image16x16>
    <image32x32>icon/icon-32.png</image32x32>
    <image48x48>icon/icon-48.png</image48x48>
    <image128x128>icon/icon-128.png</image128x128>
  </icon>

  <allowBrowserInvocation>true</allowBrowserInvocation>

</application>
    
    
====================================
2.11.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>AIR Cookbook</name>
    <version>1.1</version>
    <description>This AIR application provides code samples from the AIR Cookbook 
from O'Reilly.</description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

  <installFolder>OReilly</installFolder>
  <programMenuFolder>AIR Cookbook</programMenuFolder>

  <icon>
    <image16x16>icon/icon-16.png</image16x16>
    <image32x32>icon/icon-32.png</image32x32>
    <image48x48>icon/icon-48.png</image48x48>
    <image128x128>icon/icon-128.png</image128x128>
  </icon>

  <allowBrowserInvocation>true</allowBrowserInvocation>
  <customUpdateUI>true</customUpdateUI>

</application>
    
    
====================================
2.12.1

private var airApplicationVersion:String = "";

private function getVersion():void
{
    // Get the Application Descriptor File
    var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
    // Define the Default AIR Namespace
    var air:Namespace = appXML.namespaceDeclarations()[0];
    // Use E4X to Extract the Application Version
    this.airApplicationVersion = appXML.air::version;
}
    
    
====================================
2.12.2

var airApplicationVersion = "";

function getVersion()
{
    // Get Application Descriptor File
    var appXML = air.NativeApplication.nativeApplication.applicationDescriptor;
    // Parse the Application Descriptor File as XML
    var xmlObject = (new DOMParser()).parseFromString(appXML, "text/xml");
    // Get the Needed Values from the XML
    airApplicationVersion =
        xmlObject.getElementsByTagName('version')[0].firstChild.nodeValue;
}
    
    
====================================
2.13.1

<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.5">

    <id>com.oreilly.aircookbook</id>
    <filename>AIRCookbook</filename>
    <name>
        <text xml:lang="en">AIR Cookbook</text>
    </name>
    <version>1.1</version>
    <description>
        <text xml:lang="en"> This AIR application provides code samples from the 
AIR Cookbook from O'Reilly.</text>
    </description>
    <copyright>2008 O'Reilly, Inc.</copyright>

    <initialWindow>
        <content>AIRCookbook.swf</content>
        <systemChrome>standard</systemChrome>
        <transparent>false</transparent>
        <visible>true</visible>
        <width>640</width>
        <height>480</height>
        <x>10</x>
        <y>10</y>
        <minSize>320 240</minSize>
        <maxSize>800 600</maxSize>
        <maximizable>true</maximizable>
        <minimizable>true</minimizable>
        <resizable>true</resizable>
  </initialWindow>

  <installFolder>OReilly</installFolder>
  <programMenuFolder>AIR Cookbook</programMenuFolder>

  <icon>
    <image16x16>icon/icon-16.png</image16x16>
    <image32x32>icon/icon-32.png</image32x32>
    <image48x48>icon/icon-48.png</image48x48>
    <image128x128>icon/icon-128.png</image128x128>
  </icon>

  <allowBrowserInvocation>true</allowBrowserInvocation>
  <customUpdateUI>true</customUpdateUI>

</application>
    
    
==================
 No newline at end of file
+1463 −0

File added.

Preview size limit exceeded, changes collapsed.

+256 −0
Changes for 9780596522506-code_excerpts/ch04.txt: 256 added lines, 0 removed lines.
Original line number Diff line number Diff line
chapter: Screens
==================
4.1.1

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
    xmlns:mx="http://www.adobe.com/2006/mxml"
    horizontalAlign="center" verticalAlign="middle">

    <mx:Script>
          <![CDATA[

               import flash.display.Screen;

               private function handleClick(event:MouseEvent):void {
                     var centerX:Number = Screen.mainScreen.bounds.width / 2;
                     var centerY:Number = Screen.mainScreen.bounds.height / 2
                     nativeWindow.x = centerX - (nativeWindow.width / 2);
                     nativeWindow.y = centerY - (nativeWindow.height / 2);
               }

          ]]>
    </mx:Script>

    <mx:Button id="centerButton"
          click="handleClick(event)"
          label="Center Window" />

</mx:WindowedApplication>
    
    
====================================
4.1.2

<html>
<head>
    <title>Entry 4.1 - Center a Window</title>

    <script type="text/javascript" src="AIRAliases.js"></script>
    <script type="text/javascript">
        function handleClick(){
            var centerX = air.Screen.mainScreen.bounds.width / 2;
            var centerY = air.Screen.mainScreen.bounds.height / 2;
            window.nativeWindow.x = centerX - (window.nativeWindow.width / 2);
            window.nativeWindow.y = centerY - (window.nativeWindow.height / 2);
        }
    </script>
</head>

<body>
    <input id="centerButton" type="button" value="Center Window" 
onclick="handleClick()" />
</body>
</html>
    
    
====================================
4.2.1

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    creationComplete="handleCreationComplete()">

    <mx:Script>
          <![CDATA[
               import mx.controls.Alert;
               import flash.display.Screen;
               import mx.collections.ArrayCollection;

               [Bindable]
               private var screens:ArrayCollection;

               private function handleCreationComplete():void {
                     screens = new ArrayCollection();
                     var output:String = "";
                     var screen:Screen;
                     for(var i:uint = 0; i < Screen.screens.length; i++) {
                          screen = Screen.screens[i];
                          output = "Screen " + i + " - ";
                          output += "Width: " + screen.bounds.width;
                          output += " Height: " + screen.bounds.height;
                          screens.addItem({ label: output });
                     }
               }

               private function handleClick(event:MouseEvent):void {
                     if(monitorButtonGroup.selectedValue != null) {
                          var selectedVal:Object = monitorButtonGroup.selectedValue;

                          var screen:Screen = Screen.screens[selectedVal] as Screen;
                          var centerX:Number = screen.bounds.x + screen.bounds.width / 2;
                          var centerY:Number = screen.bounds.y + screen.bounds.height / 2;
                          nativeWindow.x = centerX - (nativeWindow.width / 2);
                          nativeWindow.y = centerY - (nativeWindow.height / 2);
                     } else {
                          mx.controls.Alert.show("Please Select a Monitor","");
                     }
               }

          ]]>
    </mx:Script>

    <mx:RadioButtonGroup id="monitorButtonGroup" />

    <mx:Repeater id="screensRepeater" dataProvider="{screens}">
          <mx:RadioButton
               id="monitorsButton"
               group="{monitorButtonGroup}"
               value="{screensRepeater.currentIndex}"
               width="100%"
               label="{screensRepeater.currentItem.label}" />
    </mx:Repeater>

    <mx:Button id="centerButton"
          click="handleClick(event)"
          label="Center on Selected Monitor" />

</mx:WindowedApplication>
    
    
====================================
4.2.2

<html>
<head>
    <title>Entry 4.2 - Multiple Monitors</title>

    <script type="text/javascript" src="AIRAliases.js"></script>
    <script type="text/javascript">
      function populateScreens() {
               var form = document.getElementById('radioButtons');
               for(i=0; I < air.Screen.screens.length; i++) {
                     var screen = air.Screen.screens[i];
                     var rb = document.createElement('input');
                     rb.type='radio';
                     rb.name='screens';
                     rb.value=i;
                     form.appendChild(rb);
                     form.innerHTML += 'Screen ' + i + ' - '
                     form.innerHTML += 'Width: ' + screen.bounds.width;
                     form.innerHTML += ' Height: ' + screen.bounds.height;
                     form.innerHTML += '<br />';
               }
          }
          function handleClick() {
               var buttons = document.forms['screensForm'].elements['screens'];
               var selectedValue;
               for( i=0; i<buttons.length;i++) {
                     if( buttons[i].checked) {
                           selectedValue = buttons[i].value;
                     }
               }
               if (selectedValue) {
                     var screen = air.Screen.screens[selectedValue];
                     var centerX = screen.bounds.x + screen.bounds.width / 2;
                     var centerY = screen.bounds.y + screen.bounds.height / 2;
                     window.nativeWindow.x = centerX - (window.nativeWindow.width / 2);
                     window.nativeWindow.y = centerY - (window.nativeWindow.height / 2);
               } else {
                     alert('Please Select a Screen');
               }
          }
    </script>
</head>

<body onload="populateScreens()" style="text-align:center;">
    <form id="radioButtons" name="screensForm"></form>
    <br />
    <input type="button" value="Center on Selected Screen" onclick="handleClick()" />
</body>
</html>
    
    
====================================
4.3.1

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    moving="handleMove(event)"
    creationComplete="handleMove(event)">
    width="320" height="240">

    <mx:Script>
          <![CDATA[
               import mx.collections.ArrayCollection;

               [Bindable]
               private var monitors:ArrayCollection = new ArrayCollection();

               private function handleMove(event:Event):void {
                     monitors.removeAll();
                     var windowBounds:Rectangle = this.nativeWindow.bounds;
                     var screens:Array = Screen.getScreensForRectangle(windowBounds);

                     var output:String = "";
                     var screen:Screen;
                     for( var i:uint = 0; i < screens.length; i++ ) {
                          screen = screens[i];
                          output = "Screen " + i + " - ";
                          output += "Width: " + screen.bounds.width;
                          output += " Height: " + screen.bounds.height;
                          monitors.addItem({ label: output });
                     }
               }
          ]]>
    </mx:Script>

    <mx:Label text="Occupied Screens" fontWeight="bold" />
    <mx:List id="monitorsList" dataProvider="{monitors}" width="100%" height="100%" />


</mx:WindowedApplication>
    
    
====================================
4.3.2

<html>
<head>
    <title>Entry 4.3 - Get Current Application Screens</title>

    <script type="text/javascript" src="AIRAliases.js"></script>
    <script type="text/javascript">
          window.nativeWindow.addEventListener(air.NativeWindowBoundsEvent.MOVING, 
handleMove);

          function handleMove(event) {
               var listing = document.getElementById('listing');
               while(listing.hasChildNodes()) {
                     listing.removeChild(listing.firstChild);
               }
               var screens = 
air.Screen.getScreensForRectangle(window.nativeWindow.bounds);
               for(i=0;i < screens.length;i++) {
                     var newDiv = document.createElement('div');
                     newDiv.innerHTML += "Screen " + i;
                     newDiv.innerHTML += " WIDTH: " + screens[i].bounds.width;
                     newDiv.innerHTML += " HEIGHT: " + screens[i].bounds.height;
                     listing.appendChild(newDiv);
               }
          }
    </script>
</head>

<body onload="handleMove(event)" style="text-align:center;">
    <strong>Occupied Screens</strong>
    <div id="listing"></div>
</body>
</html>
    
    
==================
 No newline at end of file
+1381 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading