0% found this document useful (0 votes)
50 views

Slide 37 - First Hello World Application: Id "Mypanel"

The document contains examples of code using XML and E4X (ECMAScript for XML) in Flex/ActionScript applications. It includes code snippets demonstrating how to access and manipulate XML data using E4X expressions to select nodes, attributes, and fragments. Buttons are included to "execute" each example by displaying the results of the E4X expressions. The examples cover basic node selection as well as more advanced techniques like filtering, combining expressions, accessing descendants and attributes.

Uploaded by

AnkitJain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Slide 37 - First Hello World Application: Id "Mypanel"

The document contains examples of code using XML and E4X (ECMAScript for XML) in Flex/ActionScript applications. It includes code snippets demonstrating how to access and manipulate XML data using E4X expressions to select nodes, attributes, and fragments. Buttons are included to "execute" each example by displaying the results of the E4X expressions. The examples cover basic node selection as well as more advanced techniques like filtering, combining expressions, accessing descendants and attributes.

Uploaded by

AnkitJain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

Slide 37 First Hello World Application

<?xml version="1.0" encoding="utf-8"?>


<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Panel id=myPanel x="334" y="227"
width="383"
height="305
layout="absolute">
<mx:TextArea x="10" y="0" width="343"
height="153"
text="Hello World!"
textAlign="center
fontFamily="Verdana"
fontSize="20"
fontWeight="bold"
color="#ff0000"/>
<mx:Button x="149" y="182" label="Goodbye"
click="myPanel.visible=(false)"/>
</mx:Panel>
</mx:Application>

Working with Video 1 Camera Stream


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import flash.media.Camera;
public var myCamera:Camera;
public function startCam():void {
myCamera = Camera.getCamera();
myVid.attachCamera(myCamera);
myVid.autoPlay;
}
]]>
</mx:Script>
<mx:Panel x="10" y="10" width="371" height="346"
layout="absolute"
title="AIR Camera Example" cornerRadius="15"
borderColor="#f01032">
<mx:VideoDisplay id="myVid"
width="331" height="254"
x="10" y="10"/>
<mx:Button x="148" y="272" label="Start"
click="startCam()"/>
</mx:Panel>
</mx:WindowedApplication>

Working with Video 2 HDTV (H.264)


<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Panel layout="absolute" top="10" right="10"
left="10" bottom="19">
<mx:VideoDisplay source="dworld720.mp4" top="0"
left="0" right="0"
bottom="0" autoPlay="true"/>
</mx:Panel>
</mx:Application>

Visual Components Data Slider


(build from Scratch)
<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="350" height="318"
creationComplete="trace()" cornerRadius="13"
backgroundGradientColors="[#ffffff, #c5ffa2]" alpha="0.27">
<mx:Script>
<![CDATA[
private function trace():void {
if (mySlider.value > 3){
myLabel.text="More than 3";
} else if (mySlider.value < 3) {
myLabel.text="Less than 3";
}
}
]]>
</mx:Script>
<mx:HSlider id="mySlider" x="44" y="19"
width="183" change="trace()"/>
<mx:Text text="{mySlider.value}" x="128" y="55"/>
<mx:Label x="44" y="55" text="Slider Trace:"/>
<mx:Label x="44" y="106" text="Hello Nobody."
width="199" height="54" fontSize="24"
id="myLabel"/>
</mx:ApolloApplication>

Visual Components Charts


(can build from Scratch)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var medalsAC:ArrayCollection = new ArrayCollection( [
{ Country: "USA", Beer: 3, hockey: 39, fun: 6 },
{ Country: "Canada", Beer: 32, hockey: 17, fun: 14 },
{ Country: "Russia", Beer: 27, hockey:27, fun: 38 } ]);
]]>
</mx:Script>
<mx:Panel title="ColumnChart and BarChart Controls Example"
height="100%" width="100%" layout="horizontal">
<mx:ColumnChart id="column" height="100%" width="45%"
paddingLeft="5" paddingRight="5"
showDataTips="true" dataProvider="{medalsAC}">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="Country"/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries xField="Country" yField="Beer" displayName="Beer"/>
<mx:ColumnSeries xField="Country" yField="hockey" displayName="Ice
Hockey Played"/>
<mx:ColumnSeries xField="Country" yField="fun" displayName="Fun
Had!"/>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{column}"/>
</mx:Panel>
</mx:Application>

Slide (clicktest.mxml)
Demo of using <mx:script> to include functionality
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
public function copy():void
{
destination.text=source.text;
destination2.text=source.text;
}
</mx:Script>
<mx:TextInput id="source" width="100" x="97" y="53" text="Copy me
places"/>
<mx:Button label="Copy" click="copy()" x="116" y="83"/>
<mx:TextInput id="destination" width="100" x="97" y="113"/>
<mx:TextInput id="destination2" text="" x="296" y="113"/>
</mx:Application>

Project Browser:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" cornerRadius="12" backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#FD0303, #FEBCBC]">
<mx:Text text="Enter URL and hit enter" fontFamily="Arial" fontSize="16"
fontWeight="bold"/>
<mx:TextInput id="urlTxt" width="100%" enter="html.location=urlTxt.text"
text="http://www.adobe.com" />
<mx:HTML id="html" width="100%" height="100%"
location="http://www.adobe.com" />
</mx:WindowedApplication>

e4x source code (Apollo Application)


<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<!--(c) 2006 Duane Nickull ([email protected]) - all rights reserved
You are free to use this sample demonstrating how to manipulate XML
data using the E4X component of ActionScript 3.0. This file is designed
to be used in the Flex builder 2.01 M3 RC1. No warranties
exist to the accuracy of this code and you agree to use it completely
at your own risk and assume all responsibilities for such use.
For more samples, check http://technoracle.blogspot.com or the Adobe
Labs website.
-->
<!--Alternative loading of XML from remote call
<mx:HTTPService id="myGMLData"
url="http://www.nickull.net/blogimages/GML.mxml"
resultFormat="e4x">
</mx:HTTPService>
-->
<mx:Script>
<![CDATA[
public var myGMLData:XML =
<MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml">
<lineStringMember value="1">
<LineString>

<coord>
<X>56.1</X>
<Y>0.45</Y>
</coord>
<coord>
<X>67.23</X>
<Y>0.98</Y>
</coord>
</LineString>
</lineStringMember>
<lineStringMember value="2">
<LineString>
<coord><X>46.71</X><Y>9.25</Y></coord>
<coord><X>56.88</X><Y>10.44</Y></coord>
</LineString>
</lineStringMember>
<lineStringMember value="3">
<LineString>
<coord><X>324.1</X><Y>219.7</Y></coord>
<coord><X>0.45</X><Y>4.56</Y></coord>
</LineString>
</lineStringMember>
</MultiLineString>

]]>
</mx:Script>
<!--Note that I am very lazy and these are not actually executing, they are simply
making pre-executed statements visible.
I have not lost any sleep over this since it demonstrates the functions nicely. If
you lose sleep, you can re-code ;-)-->
<mx:TabNavigator x="12" y="10" width="544" height="565">
<mx:Canvas label="Statements 1" width="100%" height="632">
<mx:Label id="XCoordinate" visible="false"
text="{myGMLData.lineStringMember[0].LineString.coord[1].X}" x="131" y="40"
width="305" fontWeight="bold" color="#e82d1b"/>
<mx:Button x="30" y="10" label="Execute" click="XCoordinate.visible=true"/>
<mx:Label x="129" y="12" text="lineStringMember[0].LineString.coord[0].X"
width="327.5"/>
<mx:Text x="30" y="40" text="Result:" width="72" textAlign="right"/>
<mx:HRule x="30" y="77" width="362"/>
<mx:Label id="YCoordinate" visible="false"
text="{myGMLData.lineStringMember[0].LineString.coord.Y[0]}" x="131" y="117"
width="307" fontWeight="bold" color="#e82d1b"/>
<mx:Button x="30" y="87" label="Execute" click="YCoordinate.visible=true"/>
<mx:Label x="131" y="89" text="lineStringMember[0].LineString.coord.Y[0]"
width="327.5"/>

<mx:Text x="30" y="117" text="Result:" width="72" textAlign="right"/>


<mx:HRule x="30" y="156" width="362"/>
<!--DOT::FRAGMENT: returns an XML Fragment-->
<mx:Label id="FragmentReturned" visible="false"
text="{myGMLData.lineStringMember[1]}" height="263" width="233" x="131"
y="196" fontWeight="bold" color="#e8351c"/>
<mx:Button x="30" y="166" label="Execute"
click="FragmentReturned.visible=true"/>
<mx:Label x="131" y="168" text="lineStringMember[1]" width="168"/>
<mx:Text x="30" y="196" text="Result:" width="72" textAlign="right"/>

</mx:Canvas>
<mx:Canvas label="Statements 2" width="100%" height="100%">
<!--PARENTHESIS: Filters the XML fragment based on X having an exact value of
324.1-->
<mx:Label id="Parenthesis" visible="false"
text="{myGMLData.lineStringMember.LineString.coord.(X == 324.1)}" height="68"
width="233" x="111" y="50" fontWeight="bold" color="#e8371c"/>
<mx:Button x="10" y="20" label="Execute" click="Parenthesis.visible=true"/>
<mx:Text x="10" y="50" text="Result:" width="72" textAlign="right"/>
<mx:Label x="111" y="22" text="lineStringMember.LineString.coord.(X ==
324.1)"/>
<mx:HRule x="10" y="126" width="362"/>
<!--COMBINATION example. Note use of math operators which cast values to
integers-->
<mx:Label id="combination" visible="false"
text="{myGMLData.lineStringMember..coord.(Y == 10.44)}" height="80"
width="326" x="111" y="164" fontWeight="bold" color="#e9441c"/>
<mx:Button x="10" y="138" label="Execute" click="combination.visible=true"/>
<mx:Text x="10" y="168" text="Result:" width="72" textAlign="right"/>
<mx:Label x="111" y="140" text="lineStringMember..coord.(Y == 10.44)"/>
<mx:HRule x="10" y="243" width="362"/>
<!--DESCENDENT: returns all instances of Y that are descendents of
lineStringMember-->
<mx:Label id="Descendent" visible="false"
text="{myGMLData.lineStringMember..Y}" height="87" width="235" x="111"
y="281" fontWeight="bold" color="#e9471b"/>
<mx:Button x="10" y="253" label="Execute" click="Descendent.visible=true"/>
<mx:Text x="10" y="283" text="Result:" width="72" textAlign="right"/>
<mx:Label x="111" y="255" text="lineStringMember..Y (all instances of Y)"
width="247"/>
<mx:HRule x="10" y="369" width="362"/>
<!--ATTRIBUTE: returns the attribute-->
<mx:Label id="Attribute" visible="false" text="{myGMLData.lineStringMember.
(@value = 2)}" x="111" y="405" width="261" height="105" fontWeight="bold"
color="#e9431b"/>

<mx:Text x="10" y="405" text="Result:" width="72" textAlign="right"/>


<mx:Button x="10" y="375" label="Execute" click="Attribute.visible=true"/>
<mx:Label x="111" y="377" text="lineStringMember.(@value = 2)"
width="272"/>
</mx:Canvas>
<mx:Canvas label="XML Data" width="100%" height="100%">
<!-- YEAH - this is really lame but I was sitting on a plane and wanted to make
the XML
look like it was formatted nicely. If anyone wants to redo, please be my
guest.
I hate entity references.... -->
<mx:Text x="10" y="10" text="&lt;? xml version=&quot;1.0&quot;
encoding=&quot;UTF-8&quot; ?&gt;"/>
<mx:Text x="26" y="23" text="&lt;MultiLineString
srsName=&quot;http://www.opengis.net/gml/srs/epsg.xml&quot;&gt;"/>
<mx:Text x="44" y="36" text="&lt;lineStringMember
value=&quot;1&quot;&gt;"/>
<mx:Text x="60" y="49" text="&lt;lineStringMember
value=&quot;1&quot;&gt;"/>
<mx:Text x="60" y="166" text="&lt;lineStringMember
value=&quot;2&quot;&gt;"/>
<mx:Text x="60" y="283" text="&lt;/lineStringMember&gt;"/>
<mx:Text x="60" y="296" text="&lt;lineStringMember
value=&quot;3&quot;&gt;"/>
<mx:Text x="60" y="416" text="&lt;/lineStringMember&gt;"/>
<mx:Text x="26" y="426" text="&lt;/MultiLineString&gt;"/>
<mx:Text x="77" y="62" text="&lt;LineString&gt;"/>
<mx:Text x="73" y="309" text="&lt;LineString&gt;"/>
<mx:Text x="73" y="179" text="&lt;LineString&gt;"/>
<mx:Text x="68" y="153" text="&lt;/LineString&gt;"/>
<mx:Text x="73" y="270" text="&lt;/LineString&gt;"/>
<mx:Text x="73" y="400" text="&lt;/LineString&gt;"/>
<mx:Text x="98" y="75" text="&lt;coord&gt;"/>
<mx:Text x="93" y="101" text="&lt;/coord&gt;"/>
<mx:Text x="93" y="114" text="&lt;coord&gt;"/>
<mx:Text x="93" y="140" text="&lt;/coord&gt;"/>
<mx:Text x="93" y="192" text="&lt;coord&gt;"/>
<mx:Text x="93" y="218" text="&lt;/coord&gt;"/>
<mx:Text x="93" y="231" text="&lt;coord&gt;"/>
<mx:Text x="93" y="257" text="&lt;/coord&gt;"/>
<mx:Text x="93" y="322" text="&lt;coord&gt;"/>
<mx:Text x="88" y="390" text="&lt;/coord&gt;"/>
<mx:Text x="88" y="364" text="&lt;coord&gt;"/>
<mx:Text x="88" y="348" text="&lt;/coord&gt;"/>
<mx:Text x="107" y="88" text="&lt;X&gt;56.1&lt;/X&gt;
&lt;Y&gt;0.45&lt;/Y&gt;"/>
<mx:Text x="107" y="127" text="&lt;X&gt;62.73&lt;/X&gt;
&lt;Y&gt;0.98&lt;/Y&gt;"/>
<mx:Text x="107" y="205" text="&lt;X&gt;46.71&lt;/X&gt;
&lt;Y&gt;9.25&lt;/Y&gt;"/>
<mx:Text x="107" y="244" text="&lt;X&gt;56.88&lt;/X&gt;
&lt;Y&gt;10.44&lt;/Y&gt;"/>
<mx:Text x="107" y="335" text="&lt;X&gt;324.1&lt;/X&gt;

&lt;Y&gt;219.7&lt;/Y&gt;"/>
<mx:Text x="107" y="374" text="&lt;X&gt;0.45&lt;/X&gt;
&lt;Y&gt;4.56&lt;/Y&gt;"/>
</mx:Canvas>
</mx:TabNavigator>
</mx:ApolloApplication>

You might also like