Simple Flex and Air Apps




CS174

Chris Pollett

Nov. 29, 2010

Outline

Announcements

Creating a simple program

A simple MXML file (test.mxml)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
       width="100%" height="100%" >   
   <mx:Button label="Hello World Button"></mx:Button>   
</mx:Application>

This could then be compiled by typing:

	
mxmlc test.mxml

This should produce a test.swf file.

Including your .swf file in a web page

Making an Air App

Application Descriptor File

Creating and Signing Your App

Quiz

Which of the following statements is true?

  1. Squid can be used for proxying, reverse proxying, and load balancing.
  2. For a web-site to be scalable it suffices that it can accommodate increased usage and it can accommodate an increased dataset.
  3. The latest versions of Chrome, Safari, Firefox, and IE all support the same encodings for the HTML 5 video tag.

Components

Containers and UI controls

Example 2

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  width="100%" height="100%" > 
<mx:VBox>
    <mx:HBox>
        <mx:Button> <mx:label>Button 1</mx:label></mx:Button> 
        <mx:Button label="Button 2" />
    </mx:HBox>
    <mx:ComboBox>
        <mx:dataProvider>
             <mx:ArrayCollection>
                  <mx:String>Item 1</mx:String>
                  <mx:String>Item 2</mx:String>
                  <mx:String>Item 3</mx:String>
             </mx:ArrayCollection>
        </mx:dataProvider>
    </mx:ComboBox>
    <mx:Text text="hello" width="100" height="15" />
     <mx:Text text="{input.text}" width="150" height="20" />
    <mx:TextInput id="input" />
</mx:VBox>
</mx:Application>

CSS

Example with CSS and also of TextArea and Comments

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  width="100%" height="100%" >

<!-- styles can be used with Flex (notice html style comment) -->
<mx:Style>
   /*     C style comment   */
   .red 
   {
       color: red;
   }
</mx:Style>  
    <mx:VBox>
        <mx:TextArea> <mx:text>This is some text.</mx:text></mx:TextArea> 
        <mx:TextArea width="400" height="100">
            <mx:htmlText><![CDATA[This is a  test <b>with html </b>.]]></mx:htmlText>
        </mx:TextArea>      
        <mx:Button label="Button" styleName="red" />
    </mx:VBox>       
</mx:Application>

What CSS Example Looks Like

Screenshot of an application with two textareas and using css to style a button red

Actionscript

Simple Actionscript Example

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  width="200" height="200" >
<mx:Script>
function imclicked()
{
 var a = 30;
 mx.controls.Alert.show('The world needs more lerts '+a);
 /*since this function does not specify types 
 and say what package it is in, it will generate warnings */
}
</mx:Script>
<mx:Style>
  Canvas { background-color:red; }
</mx:Style>
<mx:Canvas width="150" height="150"> 
<!--Notice how you can use a Canvas layout for positioning --> 
  <mx:Button id="bealert1"  x="20" y="30"
     label="Be A Lert 1" 
     click="mx.controls.Alert.show('The world needs more lerts'); " />

  <mx:Button id="bealert2"  left="10" bottom="40">
  <!--right and bottom based on parent container -->
      <mx:label>Be A Lert 2</mx:label> 
       <mx:click>imclicked();
       </mx:click>
   </mx:Button> 
</mx:Canvas>      
</mx:Application>

What Alert Example Looks Like

Screenshot of an application with two buttons which display alerts

What's new in Actionscript versus Javascript

More on Actionscript

Event Handling

Working with Media -- Images

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  width="400" 
    height="400" initialize="init()" >
    <mx:Script>
      <![CDATA[
        [Embed(source="me3.jpg")] /* this add me3.jpg directly into the .swf file that will be produced
                     other two images below come from external files */
        private var meAsset:Class; //will represent image file above
        private function init():void { me3.source = meAsset; }
        ]]>                                                    
    </mx:Script>
    <mx:HBox>
        <mx:Image source="me1.jpg" width="150" height="150"/> 
        <!-- need to use webserver not local filesystem -->
        <mx:Image id="me3" width="150" height="150"/> 
     </mx:HBox>   
     <mx:Image id="image2" autoLoad="false" width="150" height="150" />
     <mx:Button label="Load Image" click="image2.load('me2.jpg');" /> 
</mx:Application>

Image Example Before and After Click

Screenshot of flex app showing dynamically and statically loaded images

Video

<?xml version="1.0" encoding="utf-8" ?>
   <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="400" >
       <mx:Panel title="My Video" >
            <mx:VideoDisplay id="myViewer" source="fred_ott.flv"
                  volume="{volumeControl.value}" /> 
            <!-- note the source is an http source; trouble if play on filesystem -->
            <!-- you should look up Fred Ott -->
            <!-- you can create .flv files using ffmeg (Mac, Linux, Windows).
                   Or google for your favorite other tool. -->
            <mx:Label text="{myViewer.playheadTime.toPrecision(2)}" />
      
            <mx:ControlBar>
                 <mx:Button label="Play" click="myViewer.play();" />
                  <mx:Button label="Pause" click="myViewer.pause();" />
                  <mx:Button label="Stop" click="myViewer.stop();" />
                  <mx:HSlider id="volumeControl" maximum="1" width="80" />
            </mx:ControlBar>          
     </mx:Panel>
</mx:Application>

What Video Example Looks Like

An Screenshot of Fred Ott's Sneeze -- the first copyrighted film (1891)