<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeBlog.ch &#187; Flex</title>
	<atom:link href="http://www.codeblog.ch/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codeblog.ch</link>
	<description>Coding and more - Concrete5, Flex, JavaScript</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:10:29 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WYSIWYG Editor mit Flex</title>
		<link>http://www.codeblog.ch/de/2008/10/wysiwyg-editor-mit-flex/</link>
		<comments>http://www.codeblog.ch/de/2008/10/wysiwyg-editor-mit-flex/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 08:04:09 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=72</guid>
		<description><![CDATA[Adobe liefert Flex mit einem RichTextEditor aus. Dieser lässt sich sehr einfach einbinden und passt vom Layout her auch wunderbar zu den restlichen Flex Controls.  Dieser Editor hat aber leider eine ziemlich begrenzte Funktionalität. Bereits beim Einfügen eines Bildes scheitern wir! Dazu kommt, dass der generierte Code nicht HTML konform ist, ein direktes verwenden in [...]]]></description>
			<content:encoded><![CDATA[<p>Adobe liefert Flex mit einem RichTextEditor aus. Dieser lässt sich sehr einfach einbinden und passt vom Layout her auch wunderbar zu den restlichen Flex Controls. </p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/10/richtexteditor.png"><img class="alignnone size-medium wp-image-73" title="richtexteditor" src="http://www.codeblog.ch/wp-content/uploads/2008/10/richtexteditor.png" alt="" width="334" height="308" /></a></p>
<p>Dieser Editor hat aber leider eine ziemlich begrenzte Funktionalität. Bereits beim Einfügen eines Bildes scheitern wir! Dazu kommt, dass der generierte Code nicht HTML konform ist, ein direktes verwenden in einer HTML Ausgabe ist deswegen zum Beispiel nicht möglich.</p>
<p><span id="more-72"></span></p>
<p><strong>Alternative Lösungsmöglichkeit</strong></p>
<p>Die einzige flash-basierte Lösung die ich finden konnte, ist diese hier: <a href="http://flashtexteditor.com/flexdemo/full/">http://flashtexteditor.com/flexdemo/full</a> Sieht auf den ersten Blick nett aus, eingefügte Bilder verhalten sich aber nicht wie gewohnt und fliessen mit dem Text mit und zudem ist dieses Control inzwischen nur noch kommerziell verfügbar. </p>
<p>Wer sich mit HTML und JavaScript beschäftigt hat, wird sicherlich den einen oder anderen WYSIWYG HTML Editor gefunden haben. Um nur ein paar zu nennen:</p>
<ul>
<li><a href="http://tinymce.moxiecode.com/">http://tinymce.moxiecode.com/</a></li>
<li><a href="http://www.fckeditor.net/">http://www.fckeditor.net/</a></li>
<li><a href="http://www.wymeditor.org/">http://www.wymeditor.org/</a></li>
</ul>
<p>Wäre es nicht schön, wir könnten diese Editoren in Flex verwenden? Können wir!</p>
<p><strong>Flex mit Adobe AIR vs. Flex im Browser</strong></p>
<p>Es gibt einen Unterschied in der Art wie wir unsere Flex Anwendung starten bzw. ausführen lassen.</p>
<p>Es besteht die Möglichkeit mittels NPRuntime den Browser einzubinden, der das Flash aufgerufen hat. Details dazu findet man zum Beispiel bei Adobe: <a href="http://livedocs.adobe.com/flex/gumbo/langref/flash/external/ExternalInterface.html">http://livedocs.adobe.com/flex/gumbo/langref/flash/external/ExternalInterface.html</a></p>
<p>Auf derselben Seite findet man auch den Hinweis, dass diese Funktionalität mit Adobe AIR nicht funktioniert.</p>
<p><em>Note:</em> Adobe AIR currently does not support the ExternalInterface class.</p>
<p>In diesem Artikel wird nur eine mögliche Lösung beim Einsatz von Adobe AIR präsentiert. Der Lösungsweg über ExternalInterface dürfte aber ähnlich verlaufen.</p>
<p><a href="http://osflash.org/projects/wrapper">http://osflash.org/projects/wrapper</a></p>
<p><strong>HTML Code einbinden</strong></p>
<p>Bei einem AIR Projekt, haben wir ein zusätzliches Control zu Verfügung: mx:HTML. Dieses lässt sich wie jedes andere Control in Flex mit MXML verwenden.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">HTML</span> id=<span style="color: #ff0000;">&quot;html&quot;</span> location=<span style="color: #ff0000;">&quot;http://www.codeblog.ch&quot;</span><span style="color: #66cc66;">/&gt;</span></pre></td></tr></table></div>

<p>Wir können damit auch lokale HTML Files einbinden. Wir installieren als erstes die aktuelle TinyMCE Version. http://tinymce.moxiecode.com/download.php</p>
<p>Wir kopieren anschliessend sämtliche Files in unser Flex Projekt und erhalten diese Struktur:<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2008/10/struct.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/10/struct.png" alt="" title="struct" width="156" height="166" class="alignnone size-medium wp-image-78" /></a></p>
<p>editor.html ist nicht Teil von TinyMCE und TinyMCE.mxml ist unser Flex Control &#8211; mehr dazu später.</p>
<p><strong>Der HTML Code</strong></p>
<p>Wir könnten den ganzen HTML Code für den TinyMCE Aufruf in unserem Flex Code speichern, ich hab mich jedoch entschieden den Code in einer HTML Datei abzulegen. Der Code ist fast 1:1 aus dem TinyMCE Beispiel entnommen.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&nbsp;
&lt;style type=&quot;text/css&quot;&gt;
html, body {
	margin: 0px;
}
&lt;/style&gt;
&nbsp;
&lt;!-- TinyMCE --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jscripts/tiny_mce/tiny_mce.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	tinyMCE.init({
		mode : &quot;textareas&quot;,
		theme : &quot;simple&quot;
	});
&lt;/script&gt;
&lt;!-- /TinyMCE --&gt;
&nbsp;
&lt;/head&gt;
&lt;body&gt;
	&lt;textarea id=&quot;elm&quot; name=&quot;elm&quot; rows=&quot;15&quot; cols=&quot;80&quot; style=&quot;width: 100%;&quot;&gt;&lt;/textarea&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Ich habe versucht den Code in ein neues MXML Control zu packen. Gleich zu Beginn der vollständige Code &#8211; sind ja nur ein paar Zeilen:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">HTML</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> location=<span style="color: #ff0000;">&quot;tinymce/editor.html&quot;</span> initialize=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> htmlComplete:<span style="color: #0066CC;">Boolean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> localHtmlCode:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">null</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onHTMLLoadComplete<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> htmlCode <span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// in case the html file hasn't been loaded yet, delay the call..</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>htmlComplete<span style="color: #66cc66;">&#41;</span>
			setHtml<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">else</span>
			localHtmlCode = value;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> htmlCode<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">tinyMCE</span>.<span style="color: #006600;">triggerSave</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">elm1</span>.<span style="color: #006600;">value</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setHtml<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">tinyMCE</span>.<span style="color: #0066CC;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'elm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">setContent</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">htmlLoader</span>.<span style="color: #006600;">window</span>.<span style="color: #006600;">document</span>.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'elm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">value</span> = value;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onHTMLLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
	<span style="color: #66cc66;">&#123;</span>
		htmlComplete = <span style="color: #000000; font-weight: bold;">true</span>;
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>localHtmlCode <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
			callLater<span style="color: #66cc66;">&#40;</span>setHtml,<span style="color: #66cc66;">&#91;</span>localHtmlCode<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:HTML<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Als Basis für unser Control dient mx:HTML. Wir fügen lediglich die Eigenschaft htmlCode hinzu, um den Inhalt von TinyMCE zu ändern und auslesen.</p>
<p>Dazu müssen wir lediglich eine Methode mit dem Zusatz &#8220;get&#8221; ausstatten und eine mit &#8220;set&#8221;.</p>
<p>Nun hatte ich jedoch das Problem, dass TinyMCE noch nicht komplett geladen war, als ich versucht habe die Eigenschaft htmlCode zu verändern. Ich hab deswegen, eine noch nicht vollständig getestete, Lösung versucht umzusetzen &#8211; durch das abfangen des Events &#8220;COMPLETE&#8221;, wird uns mitgeteilt wann das HTML Control geladen ist, wurde die Eigenschaft htmlCode von vorher gesetzt (htmlComplete == false), so wird nachdem das Control geladen ist, der Code mittels callLater gesetzt. callLater sollte eigentlich schon selber erst ausgeführt werden, wenn das Control fertig geladen ist. In meinem Fall hat dies jedoch nicht gereicht. (bin für jeden Hinweis dankbar).</p>
<p>Alles speichern und schon haben wir im Flex Builder ein neues Control in der Rubrik &#8220;Custom&#8221; zur Verfügung. Per Drag&#8217;n'Drop einfügen, Projekt starten!<br />
<a href="http://www.codeblog.ch/wp-content/uploads/2008/10/tinymce.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/10/tinymce-475x145.png" alt="" title="tinymce" width="475" height="145" class="alignnone size-medium wp-image-86" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/10/wysiwyg-editor-mit-flex/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Web Applikation mit Adobe AIR</title>
		<link>http://www.codeblog.ch/de/2008/09/web-applikation-mit-adobe-air/</link>
		<comments>http://www.codeblog.ch/de/2008/09/web-applikation-mit-adobe-air/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 09:06:14 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=44</guid>
		<description><![CDATA[Von Adobe gibt es seit einiger Zeit eine Technologie mit dem Namen AIR. Adobe AIR erlaubt es, Appliationen welche fürs Web entwickelt wurden, besser ins lokale Betriebssystem zu integrieren. Man hat Zugriff auf eine Reihe von Funktionen welche Webapplikationen normalerweise nicht haben (Zwischenablage, Dateisystem usw.) Die Applikation kann direkt aus dem Startmenü (bei Windows) geöffnet [...]]]></description>
			<content:encoded><![CDATA[<p>Von Adobe gibt es seit einiger Zeit eine Technologie mit dem Namen <a href="http://www.adobe.com/products/air/" target="_blank">AIR</a>. Adobe AIR erlaubt es, Appliationen welche fürs Web entwickelt wurden, besser ins lokale Betriebssystem zu integrieren.</p>
<ul>
<li>Man hat Zugriff auf eine Reihe von Funktionen welche Webapplikationen normalerweise nicht haben (Zwischenablage, Dateisystem usw.)</li>
<li>Die Applikation kann direkt aus dem Startmenü (bei Windows) geöffnet werden.</li>
</ul>
<div>Adobe AIR unterstützt dabei HTML + Javascript, AJAX Appliationen. Natürlich wird aber auch die hauseigene Technologie Flash und damit auch Flex unterstützt.</div>
<div></div>
<p><span id="more-44"></span></p>
<p>Bevor wir beginnen, muss zuerst das (frei verfügbare) AIR SDK installiert werden. Dazu von dieser Seite das entsprechende ZIP herunterladen und installieren. <a href="http://www.adobe.com/products/air/tools/sdk/">http://www.adobe.com/products/air/tools/sdk/<br />
</a></p>
<p><strong>HTML Applikation mit AIR starten</strong></p>
<p>Neben dem bekannten HTML und JavaScript Code brauchen wir für Adobe AIR lediglich eine simple XML Datei.</p>
</p>
<p>Wir erstellen eine Datei mit dem Namen hellocodeblog-app.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/application/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>hellocodeblog.html.hellocodeblog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>hellocodeblog<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>hellocodeblog.html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>400<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>200<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Als nächstes brauchen wir wie gewohnt ein bisschen HTML Code. Damit wir die AIR Funktionalität komplett nutzen können, binden wir die Datei AIRAliases.js ein. In diesem Beispiel werden wir sie allerdings nicht verwenden.</p>
<p>Die Datei hellocodeblog.html enthält diesen Code</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Hello CodeBlog&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;Hello CodeBlog!&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p><strong>Applikation starten</strong><br />
Unsere Applikation starten wir nun indem wir der Datei adl.bat aus dem AIR SDK unsere XML Datei übergeben:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/09/hellocodeblog.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/09/hellocodeblog-475x166.png" alt="" title="hellocodeblog" width="475" height="166" class="alignnone size-medium wp-image-45" /></a></p>
<p><strong>Applikation publizieren</strong></p>
<p>Wir können unsere Applikation mit AIR gleich verpacken so dass wir ohne das SDK die Applikation starten können.</p>
<p>Applikationen müssen zertifiziert werden. Wenn man bereits ein Zertifikat hat, natürlich dieses verwenden. In unserem Fall erstellen wir uns aber ein eigenes. Dazu brauchen wir das Tool adt welches sich ebenfalls im bin Verzeichnis des AIR SDKs befindet.</p>
<pre>
adt -certificate -cn SelfSigned 1024-RSA codeBlog.pfx ein-password
</pre>
<p>Anschliessend rufen wir das Tool adt mit anderen Parametern auf um unsere Files in eine AIR Datei zu packen. Diese kann anschliessend mit einem Doppelklick installiert werden.</p>
<pre>adt -package -storetype pkcs12 -keystore codeBlog.pfx HelloCodeBlog.air hellocodeblog-app.xml hellocodeblog.html</pre>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/09/install.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/09/install-475x370.png" alt="" title="install" width="475" height="370" class="alignnone size-medium wp-image-48" /></a></p>
<p>Anschliessend läuft unsere Applikation ohne das Konsolen Fenster und einem SDK Tool.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/09/running.png"><img src="http://www.codeblog.ch/wp-content/uploads/2008/09/running.png" alt="" title="running" width="400" height="200" class="alignnone size-medium wp-image-49" /></a></p>
<p><strong>Weitere Informationen</strong></p>
<p>Von Adobe gibt es ein gut strukturierter Büchlein in Englisch welches in Kapitel 4 die Möglichkeiten beschreibt die AIR bietet. <a href="http://onair.adobe.com/files/AIRforJSDevPocketGuide.pdf">http://onair.adobe.com/files/AIRforJSDevPocketGuide.pdf</a></p>
<p><strong>Update 18. September 2008</strong></p>
<p>Scheint so als gäbe es einige Einschränkungen bei der Integration ins Betriebssystem. Die trivial wirkende Anforderung einen Prozess zu starten erweist sich als deutlich komplexer als erwartet. Bisher scheint dies lediglich über einen zusätzlichen &#8220;Proxy&#8221; machbar zu sein. <a href="http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/">http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/</a></p>
<p>Warten wir mal ab und schauen was Adobe vielleicht nachliefert. Einfache Web Applikationen vom Desktop aus starten ist ja nett, aber wirklich konkurrenzfähig mit klassischen Applikationen ist das in dieser Form sicherlich nicht. Keine direkte Nutzung von lokalen (nativen) Bibliotheken usw&#8230;</p>
<p><strong>Update 18. September 2008 &#8211; 2</strong></p>
<p>Es scheint auch ohne Zusatzsoftware zu gehen, allerdings auch nicht wirklich elegant. Dieser Code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> air.<span style="color: #660066;">URLRequest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;file://c:/windows/notepad.exe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
air.<span style="color: #660066;">navigateToURL</span><span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>scheint zu funktionieren, jedoch abhängig vom Standard Browser. URLRequest öffnet nämlich jeweils den Browser und abhängig vom Browser erhält man dann auch noch eine Warnung (als würde man einen Link im Internet anklicken). Hat man aber zum Beispiel Google&#8217;s Chrome installiert, so wird die Datei heruntergeladen, auch nicht wirklich optimal&#8230;</p>
<p><strong>Update 8. Oktober 2008</strong></p>
<p>Unter Windows kann man diese Erweiterung nutzen: <a href="http://aperture.fluorinefx.com/">http://aperture.fluorinefx.com/</a>. Damit kann man sehr einfach Prozesse starten, Screenshots erstellen und auf gewisse Outlook Daten zugreifen. Allerdings nur für Windows!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/09/web-applikation-mit-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AMFPHP Methoden mit Parametern</title>
		<link>http://www.codeblog.ch/de/2008/05/amfphp-methoden-mit-parametern/</link>
		<comments>http://www.codeblog.ch/de/2008/05/amfphp-methoden-mit-parametern/#comments</comments>
		<pubDate>Fri, 09 May 2008 14:44:25 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=26</guid>
		<description><![CDATA[Nachdem ich doch mehr als 5 Minuten benötigt habe, um eine PHP Methode die ich mittels AMFPHP zur Verfügung gestellt habe aufzurufen, hier ein weiterer Mini-Artikel zum Thema Flex und AMFPHP. In der Praxis will man ja meistens nicht einfach eine Methode ohne Argumente aufrufen. Bei mir war es zum Beispiel eine Methode die Datensätze [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich doch mehr als 5 Minuten benötigt habe, um eine PHP Methode die ich mittels AMFPHP zur Verfügung gestellt habe aufzurufen, hier ein weiterer Mini-Artikel zum Thema Flex und AMFPHP.</p>
<p>In der Praxis will man ja meistens nicht einfach eine Methode ohne Argumente aufrufen. Bei mir war es zum Beispiel eine Methode die Datensätze zurückliefert. Dort wollte ich ein paar Daten übergeben, so dass man nicht unnötig viele Datensätze übertragen muss. Das schöne oder auch unschöne an Flex, je nach Anwendungsfalls, ist ja, dass wir lediglich die Daten vom Server zum Client übertragen müssen. Das GUI wird einmalig beim Start übertragen und läuft dann auf dem Client. Bei HTML (AJAX ausgenommen) übertragen wir ja immer eine ganze Reihe Anweisungen die das Layout betreffen. Ein Webdesigner beklagt sich darüber wohl kaum noch, ein Softwareentwickler vielleicht schon eher.</p>
<p><span id="more-26"></span></p>
<p>Damit das wirklich ein Mini-Artikel bleibt auch nur ein Auszug aus dem PHP Code. Unsere Methode die wir aufrufen wollen. Sollte nicht klar sein, wie man diese mittels AMFPHP Flex zur Verfügung stellen kann. Im Artikel <a href="http://www.codeblog.ch/2008/04/datenaustausch-mit-amfphp-und-flex/">http://www.codeblog.ch/2008/04/datenaustausch-mit-amfphp-und-flex/</a> ist dies beschrieben.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$transactionId</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span></pre></div></div>

<p>Wir benötigen auch in diesem Fall (ausser wir geben die Adresse zu gateway.php fix an) eine Konfigurationsdatei, welche wir mxmlc mit dem Parameter &#8220;-services&#8221; übergeben.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfphp-flashremoting-service&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.services.RemotingService&quot;</span> <span style="color: #000066;">messageTypes</span>=<span style="color: #ff0000;">&quot;flex.messaging.messages.RemotingMessage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;destination</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfphp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;amfphp-channel&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/destination<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel-definition</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfphp-channel&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;mx.messaging.channels.AMFChannel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://localhost/amfphp/gateway.php&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.endpoints.AMFEndpoint&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel-definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Damit haben wir unsere Konfiguration in eine XML Datei ausgelagert.</p>
<p><strong>Argument übergeben &#8211; Variante 1</strong></p>
<p>Wir können direkt in der RemoteObject Definition die Argumente definieren:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:RemoteObject id=<span style="color: #ff0000;">&quot;myservice&quot;</span> destination=<span style="color: #ff0000;">&quot;amfphp&quot;</span> source=<span style="color: #ff0000;">&quot;accounting.TransactionDao&quot;</span> fault=<span style="color: #ff0000;">&quot;faultHandler(event)&quot;</span> showBusyCursor=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;</span>mx:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;load&quot;</span> result=<span style="color: #ff0000;">&quot;transactionResultHandler(event)&quot;</span><span style="color: #66cc66;">&gt;</span>
      <span style="color: #66cc66;">&lt;</span>mx:arguments<span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;</span>transactionId<span style="color: #66cc66;">&gt;</span><span style="color: #66cc66;">&#123;</span>transactionId<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&lt;/</span>transactionId<span style="color: #66cc66;">&gt;</span>
      <span style="color: #66cc66;">&lt;/</span>mx:arguments<span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;/</span>mx:method<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:RemoteObject<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Dies macht vorallem dann Sinn, wenn wir Werte übergeben wollen, die schon zur Verfügung stehen. Zum Beispiel Formularfelder oder sonstige Werte die &#8220;bindable&#8221; sind.</p>
<p>Das obige Beispiel sucht einfachheitshalber nur eine Variable transactionId, welche sich folgendermassen definieren lässt:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
<span style="color: #000000; font-weight: bold;">var</span> transactionId:<span style="color: #0066CC;">String</span>;</pre></div></div>

<p>Wollen wir die Methode aufrufen, so müssen wir sicherstellen, dass die Variable auch einen Wert enthält:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
   transactionId = <span style="color: #cc66cc;">123</span>;
   myservice.<span style="color: #0066CC;">load</span>.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Man erkennt ziemlich schnell, dass dieser Code etwas fraglich ist &#8211; wieso sollten wir eine &#8220;globale&#8221; Variable definieren um einer Methode einen Wert zu übergeben? Wie vorhin erwähnt macht dies vorallem dann Sinn, wenn die Variable bereits vorhanden ist. Ist dies nicht der Fall, so ist Variante 2 wohl zu bevorzugen.</p>
<p>Von Adobe gibt es übrigens auch einen Artikel der dieses Binding Verfahren beschreibt:<br />
<a href="http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&#038;file=dataservices_099_11.html">http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&#038;file=dataservices_099_11.html</a></p>
<p><strong>Argument übergeben &#8211; Variante 2</strong></p>
<p>Wollen wir lokal verfügbare Daten übergeben, so sieht die Angelegenheit noch etwas einfacher aus. Wir definieren bei RemoteObject keine Argumente mehr:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:RemoteObject id=<span style="color: #ff0000;">&quot;myservice&quot;</span> destination=<span style="color: #ff0000;">&quot;amfphp&quot;</span> source=<span style="color: #ff0000;">&quot;accounting.TransactionDao&quot;</span> fault=<span style="color: #ff0000;">&quot;faultHandler(event)&quot;</span> showBusyCursor=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;</span>mx:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;load&quot;</span> result=<span style="color: #ff0000;">&quot;transactionResultHandler(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:RemoteObject<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>und wer hätte es gedacht, wir können die Argumente direkt übergeben.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
   myservice.<span style="color: #0066CC;">load</span>.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">123</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Zugegeben etwas offensichtlich, ich hab aber trotzdem ein paar Minuten benötigt um die zwei unterschiedlichen Methoden zu entdecken &#8211; vielleicht hilft&#8217;s ja jemandem!</p>
<p>Natürlich hätte man bei Adobe auch dazu einen Artikel gefunden. <a href="http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&#038;file=dataservices_099_11.html">http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&#038;file=dataservices_099_11.html</a> Wenn man nur gleich an der richtigen Stelle suchen würde, wäre das alles kein Problem gewesen!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/05/amfphp-methoden-mit-parametern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datenaustausch mit AMFPHP und Flex</title>
		<link>http://www.codeblog.ch/de/2008/04/datenaustausch-mit-amfphp-und-flex/</link>
		<comments>http://www.codeblog.ch/de/2008/04/datenaustausch-mit-amfphp-und-flex/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 12:44:21 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=21</guid>
		<description><![CDATA[Bereits in einem älteren Artikel: Datenaustausch mit Flex, hab ich erwähnt wie man Daten von einem PHP Script in einer Flex Anwendung bringen kann. Das PHP Script war dort jedoch sehr primitiv und sollte so nicht in die Internet-Wildnis gelassen werden. In diesem Beitrag wollen wir mittels AMFPHP etwas eleganter Daten von einem serverseitigen PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Bereits in einem älteren Artikel: <a href="http://www.codeblog.ch/2008/04/datenaustausch-mit-flex/">Datenaustausch mit Flex</a>, hab ich erwähnt wie man Daten von einem PHP Script in einer Flex Anwendung bringen kann. Das PHP Script war dort jedoch sehr primitiv und sollte so nicht in die Internet-Wildnis gelassen werden.</p>
<p>In diesem Beitrag wollen wir mittels <a href="http://www.amfphp.org/">AMFPHP</a> etwas eleganter Daten von einem serverseitigen PHP Script in einer Flex Anwendung bringen. Adobe bietet mit <a href="http://www.adobe.com/products/flashremoting/">Flash Remoting MX</a> selber eine Komponente an um dies zu bewerkstelligen. Ich versuche aber bewusst freie verfügbare Komponenten einzusetzen, da das &#8220;Spielen&#8221; etwas mehr Spass macht, wenn man kein Geld ausgeben muss. Es gäbe noch eine weitere Alternative &#8211; <a href="http://www.ghostwire.com/go/28">PHPObject</a>, diese wird hier aber nicht weiter erwähnt, ev. kommt dazu aber noch ein weiterer Artikel.</p>
<p><span id="more-21"></span></p>
<p><strong>Vorbereitung</strong></p>
<li>Flex SDK, wer&#8217;s noch nicht hat &#8211; zurück an der Start: <a href="http://www.codeblog.ch/2008/04/einstieg-in-adobe-flex-3/">Einstieg in Adobe Flex 3</a></li>
<li>Webserver mit PHP Unterstützung</li>
<li><a href="http://sourceforge.net/project/showfiles.php?group_id=72483#files">AMFPHP</a> herunterladen &#038; installieren. Am besten, so dass es gleich mit &#8220;http://localhost/amfphp&#8221; ansprechbar ist. Dadurch funktionieren alle Pfadangaben.</li>
<p><strong>PHP Script</strong></p>
<p>In diesem Beispiel wird in einem PHP Script ein Array mit zwei Einträge erstellt, welches mittels AMFPHP publiziert wird. Mit AMFPHP kann man sehr einfach mit Remoting Daten zur Verfügung stellen.</p>
<p>Wir definieren dazu lediglich eine Klasse &#8220;Topic&#8221; welche die Felder für unsere Daten enthält. Und eine Service Klasse, welche die Daten ausliest und zurückgibt. Da wir unseren Service in einem eigenen Ordner/Namespace/Package haben wollen, definieren wir zudem _explictType.</p>
<p>Wichtig ist hier, dass am Ende der Datei keine Leerzeichen stehen. AMFPHP modifiziert den &#8220;Header&#8221; &#8211; wer schon mit PHP ein paar Erfahrungen gesammelt hat, weiss, dass man keine Ausgaben machen darf, wenn man den Header modifizieren will. Zeilenumbrüche oder Leerzeichen sind auch Zeichen!</p>
<p>Wer dies nicht beachtet, wird die nette Meldung &#8220;Client.Error.DeliveryInDoubt&#8221; erhalten. Heisst ungefähr soviel wie Daten wurden in einem nicht brauchbaren Format übergeben. Eine PHP Fehlermeldung ist in unserem Fall nicht brauchbar!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Topic <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$_explicitType</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;codeblog.Topic&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$topic</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$author</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> TopicService
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">function</span> getTopics<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$topics</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$topic</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Topic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SuperMario'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'super@mario'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topic</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gameplay'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'luigi'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topics</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$topic</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$topic</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Topic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">author</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Laubi'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'laubi@codeblog'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topic</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'flex remoting'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'siehe codeblog.ch'</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$topics</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$topic</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$topics</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Als TopicService.php, wie auf diesem Screenshot abgebildet, speichern:<br />
<a href='http://www.codeblog.ch/wp-content/uploads/2008/04/amfphp.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/amfphp.png" alt="" title="amfphp" width="406" height="198" class="alignnone size-medium wp-image-22" /></a></p>
<p><strong>Service Konfiguration</strong></p>
<p>Damit wir die Adresse des Services nicht in den Code schreiben müssen, erstellen wir eine Datei mit dem Namen services-config.xml welche dies übernimmt:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfphp-flashremoting-service&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.services.RemotingService&quot;</span> <span style="color: #000066;">messageTypes</span>=<span style="color: #ff0000;">&quot;flex.messaging.messages.RemotingMessage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;destination</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfphp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;amfphp-channel&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
					<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/destination<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel-definition</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;amfphp-channel&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;mx.messaging.channels.AMFChannel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://localhost/amfphp/gateway.php&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;flex.messaging.endpoints.AMFEndpoint&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel-definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channels<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Wichtig sind hier folgende Dinge:</p>
<li>Die ID bei destination: amfphp. Diesen Namen benötigen wir um den Service aus dem Action Script anzusprechen</li>
<li>Das Attribut ref bei channel muss zur channel-definition passen</li>
<li>Bei endpoint muss die korrekte Adresse eingetragen sein</li>
<p>Damit diese zusätzliche Konfigurationsdatei beim Erstellen beachtet wird, müssen wir sicherstellen, dass mxmlc dieser Zusatz übergeben wird: &#8220;-services services-config.xml&#8221;. Bei FlashDevelop geht dies natürlcih auch:<br />
<a href='http://www.codeblog.ch/wp-content/uploads/2008/04/fd-amfphp.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/fd-amfphp.png" alt="" title="fd-amfphp" width="372" height="376" class="alignnone size-medium wp-image-23" /></a></p>
<p><strong>Die Flex Anwendung</strong></p>
<p>Die Flex Anwendung sollen die Daten in einer Liste bzw. Grid ausgeben und beim Selektieren eines Eintrages dessen Details anzeigen. Dazu benötigen wir zwei Dateien. Die erste Datei Topic.as dient uns als Struktur um die Daten entgegen zu nehmen.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package codeblog
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#91;</span>RemoteClass<span style="color: #66cc66;">&#40;</span>alias=<span style="color: #ff0000;">&quot;codeblog.Topic&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Topic
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> author:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> email:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> topic:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">message</span>:<span style="color: #0066CC;">String</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Die zweite Datei enthält das MXML Layout und die Anweisungen Daten vom Service zu holen. Als erstes braucht es dazu eine Definition damit die Flex Anwendung unseren Service findet.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:RemoteObject id=<span style="color: #ff0000;">&quot;myservice&quot;</span> source=<span style="color: #ff0000;">&quot;codeblog.TopicService&quot;</span> destination=<span style="color: #ff0000;">&quot;amfphp&quot;</span> fault=<span style="color: #ff0000;">&quot;faultHandler(event)&quot;</span> showBusyCursor=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:method <span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;getTopics&quot;</span> result=<span style="color: #ff0000;">&quot;getTopicsHandler(event)&quot;</span> fault=<span style="color: #ff0000;">&quot;faultHandler(event)&quot;</span> <span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:RemoteObject<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Wir nun die Send Methode aufgerufen, so wird die Anfrage gestartet und die Methode getTopicsHandler wird aufgerufen bzw. faultHandler bei einem Fehler.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">myservice.<span style="color: #006600;">getOperation</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'getTopics'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
...
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> faultHandler<span style="color: #66cc66;">&#40;</span>fault:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span>fault.<span style="color: #006600;">fault</span>.<span style="color: #006600;">faultString</span>, fault.<span style="color: #006600;">fault</span>.<span style="color: #006600;">faultCode</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getTopicsHandler<span style="color: #66cc66;">&#40;</span>ev:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    dp = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span>ArrayUtil.<span style="color: #006600;">toArray</span><span style="color: #66cc66;">&#40;</span>ev.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Den vollständigen Code findet ihr am Ende des Artikels. Und wenn alles geklappt hat, solltet FlashDevelop nach dem Betätigen von F5 das hier anzeigen:<br />
<a href='http://www.codeblog.ch/wp-content/uploads/2008/04/fd-remoting.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/fd-remoting.png" alt="" title="fd-remoting" width="360" height="394" class="alignnone size-medium wp-image-24" /></a></p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flexremoting.zip'>Quellcode der Flex Anwendung ohne AMFPHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/datenaustausch-mit-amfphp-und-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fraktal mit Flex</title>
		<link>http://www.codeblog.ch/de/2008/04/fraktal-mit-flex/</link>
		<comments>http://www.codeblog.ch/de/2008/04/fraktal-mit-flex/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 12:11:23 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=18</guid>
		<description><![CDATA[Flex benötigt zur Ausführung Flash und bekanntlich ist Flash ja früher ein Tool gewesen um Animationen und vergleichbares zu erstellen. Fälschlicherweise denken auch heute noch viele an ein besseres Powerpoint wenn sie das Wort &#8220;Flash&#8221; hören, aber dies ist ein anderes Thema. Anstelle der grafischen Art und Weise wie man eine Flash Animation erstellen kann, [...]]]></description>
			<content:encoded><![CDATA[<p>Flex benötigt zur Ausführung Flash und bekanntlich ist Flash ja früher ein Tool gewesen um Animationen und vergleichbares zu erstellen. Fälschlicherweise denken auch heute noch viele an ein besseres Powerpoint wenn sie das Wort &#8220;Flash&#8221; hören, aber dies ist ein anderes Thema.</p>
<p>Anstelle der grafischen Art und Weise wie man eine Flash Animation erstellen kann, ist es natürlich auch möglich, Bilder per Code erstellen. Wir wollen deswegen ein simples Fraktal von Flex/Flash zeichnen lassen.</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flex-fractal.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/flex-fractal.png" alt="" title="flex-fractal" width="306" height="396" class="alignnone size-medium wp-image-19" /></a></p>
<p><span id="more-18"></span></p>
<p>Der Code für die Erstellung des Fraktals, hab ich einem C-Beispiel entnommen, dessen Herkunft ich leider nicht mehr kenne. Ich hab es aber in der Kategorie &#8220;ohne Copyright&#8221; bei mir eingeordnet, sollte dies nicht stimmen, bitte melden!</p>
<p>Damit unser Fraktal gezeichnet wird, ohne dass wir 10 Tassen Kaffee trinken müssen bis etwas sichtbar ist, verwenden wir die <a href="http://livedocs.adobe.com/flex/3/langref/flash/display/BitmapData.html">BitmapData</a> Klasse. Diese Klasse ist für unsere Zwecke ideal, da wir nicht direkt auf den Monitor zeichen, sondern in eine Art 2D-Array. Würden wir jeden Pixel direkt auf den Monitor zeichnen, gäbe es sehr viele &#8220;Refreshs&#8221; der Anzeige.</p>
<p><strong>Wie kann ich mit BitmapData etwas ausgeben?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">...
<span style="color: #006600;">bmd</span> = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">300</span>, <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
bmd.<span style="color: #006600;">setPixel</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span>,0xFF0000<span style="color: #66cc66;">&#41;</span>;
img.<span style="color: #006600;">source</span> = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;</span>mx:Image id=<span style="color: #ff0000;">&quot;img&quot;</span> <span style="color: #66cc66;">/&gt;</span></pre></div></div>

<p>Dieser Code zeichnet lediglich einen roten &#8220;Pixel&#8221; an der Position 10, 10 und gibt in anschliessend im Image Objekt &#8220;img&#8221; aus. Für die Ausgabe müssen wir unser BitmapData Object in ein Bitmap Objekt umwandeln, dazu gibt es sogar einen Konstruktor, so dass wir dafür lediglich eine Zeile benötigen (new Bitmap(bmd)).</p>
<p>Mit diesem Prinzip können wir mit einer akzeptablen Performance Bilder erstellen. Selbstverständlich können wir nicht nur einzelne Pixel mit BitmapData manipulieren, es gibt zahlreiche Funktionen wie zum Beispiel <a href="http://livedocs.adobe.com/flex/3/langref/flash/display/BitmapData.html#fillRect()">fillRect</a>, wir wollen aber nicht weiter auf die Funktonen von BitmapData eingehen.</p>
<p>Damit wir die Parameter unseres Fraktals ohne Code-Änderung einstellen können, erstellen wir mit MXML ein simples Interface. Mit &#8220;mx:HSlider&#8221; stellt uns Flex ein passendes Control zur Verfügung um einen numerischen Wert grafisch zu verändern.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:HSlider id=<span style="color: #ff0000;">&quot;slider_p&quot;</span> minimum=<span style="color: #ff0000;">&quot;-5&quot;</span> maximum=<span style="color: #ff0000;">&quot;-0.7&quot;</span> value=<span style="color: #ff0000;">&quot;-1.29&quot;</span> tickColor=<span style="color: #ff0000;">&quot;black&quot;</span> snapInterval=<span style="color: #ff0000;">&quot;0.1&quot;</span> tickInterval=<span style="color: #ff0000;">&quot;0.3&quot;</span> allowTrackClick=<span style="color: #ff0000;">&quot;true&quot;</span> liveDragging=<span style="color: #ff0000;">&quot;true&quot;</span> change=<span style="color: #ff0000;">&quot;generateFractal()&quot;</span><span style="color: #66cc66;">/&gt;</span></pre></div></div>

<p>Bei jeder Änderung (change=&#8230;) führen wir die Funktion &#8220;generateFractal&#8221; aus, welche sofort das Fraktal neu zeichnet.</p>
<p>Mein Wissen bezüglich Fraktalen ist definitiv zu klein, deswegen kann ich den Code nicht weiter kommentieren. Es gibt aber zahlreiche Ressourcen im Internet wenn jemand mehr über dieses Thema wissen will.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData;
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> generateFractal<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	bmd = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">300</span>, <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
        bmd.<span style="color: #006600;">lock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> xmin:<span style="color: #0066CC;">Number</span>, xmax:<span style="color: #0066CC;">Number</span>, ymin:<span style="color: #0066CC;">Number</span>, ymax:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> fact:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1.0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> ypy:<span style="color: #0066CC;">Number</span>, x:<span style="color: #0066CC;">Number</span>, y:<span style="color: #0066CC;">Number</span>, x0:<span style="color: #0066CC;">Number</span>, y0:<span style="color: #0066CC;">Number</span>, xp:<span style="color: #0066CC;">Number</span>, yp:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> const_scr:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1.0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> deltax:<span style="color: #0066CC;">Number</span>, deltay:<span style="color: #0066CC;">Number</span>, p:<span style="color: #0066CC;">Number</span>, q:<span style="color: #0066CC;">Number</span>, ya:<span style="color: #0066CC;">Number</span>, r:<span style="color: #0066CC;">Number</span>, xkp1:<span style="color: #0066CC;">Number</span>, ykp1:<span style="color: #0066CC;">Number</span>;
	<span style="color: #000000; font-weight: bold;">var</span> npix:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">640</span>, npiy:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">480</span>;
	<span style="color: #000000; font-weight: bold;">var</span> kcolor:<span style="color: #0066CC;">int</span>;
	<span style="color: #000000; font-weight: bold;">var</span> k:<span style="color: #0066CC;">int</span>, np:<span style="color: #0066CC;">int</span>, nq:<span style="color: #0066CC;">int</span>, ipen:<span style="color: #0066CC;">int</span>;
&nbsp;
	p = slider_p.<span style="color: #006600;">value</span>;
	q = slider_q.<span style="color: #006600;">value</span>;
	xmin = slider_xmin.<span style="color: #006600;">value</span>;
	xmax = slider_xmax.<span style="color: #006600;">value</span>;
	ymin = slider_ymin.<span style="color: #006600;">value</span>;
	ymax = slider_ymax.<span style="color: #006600;">value</span>;
	kcolor = slider_kcolor.<span style="color: #006600;">value</span>;
&nbsp;
	deltax = <span style="color: #66cc66;">&#40;</span>xmax-xmin<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>npix-<span style="color: #cc66cc;">1</span>;
	deltay = <span style="color: #66cc66;">&#40;</span>ymax-ymin<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span>npiy-<span style="color: #cc66cc;">1</span>;
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>np = <span style="color: #cc66cc;">0</span>; np <span style="color: #66cc66;">&lt;</span>= npix - <span style="color: #cc66cc;">1</span>; np++<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		x0 = xmin + np<span style="color: #66cc66;">*</span>deltax;
		<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>nq = <span style="color: #cc66cc;">0</span>; nq <span style="color: #66cc66;">&lt;</span>= npiy - <span style="color: #cc66cc;">1</span>; nq++<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			y0 = ymin + nq<span style="color: #66cc66;">*</span>deltay;
			x = x0;
			y = y0;
			k  = <span style="color: #cc66cc;">0</span>;
			<span style="color: #b1b100;">do</span>
			<span style="color: #66cc66;">&#123;</span>
				xkp1 = <span style="color: #66cc66;">&#40;</span>x+y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#40;</span>x-y<span style="color: #66cc66;">&#41;</span> + p;
				ya   = x<span style="color: #66cc66;">*</span>y;
				ykp1 = ya + ya + q;
				r    = xkp1<span style="color: #66cc66;">*</span>xkp1 + ykp1<span style="color: #66cc66;">*</span>ykp1;
				k++;
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>r <span style="color: #66cc66;">&gt;</span>= kcolor<span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					ipen = <span style="color: #cc66cc;">30</span> + k;
					xp = const_scr<span style="color: #66cc66;">*</span>np;
					yp = nq;
					bmd.<span style="color: #006600;">setPixel</span><span style="color: #66cc66;">&#40;</span>xp,yp,ipen<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>k == kcolor<span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					ipen = <span style="color: #cc66cc;">1</span>;
					xp = const_scr<span style="color: #66cc66;">*</span>np;
					yp = nq;
					bmd.<span style="color: #006600;">setPixel</span><span style="color: #66cc66;">&#40;</span>xp,yp,ipen<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
&nbsp;
				x = xkp1;
				y = ykp1;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>r <span style="color: #66cc66;">&lt;</span>= kcolor <span style="color: #66cc66;">&amp;&amp;</span> k<span style="color: #66cc66;">&lt;</span>=kcolor<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
        bmd.<span style="color: #006600;">unlock</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	img.<span style="color: #006600;">source</span> = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Die Input Parameter hab ich &#8220;empirisch&#8221; auf ein Minimum bzw. Maximum beschränkt. Einige sind aber trotzdem nicht ganz optimal, so lässt sich zum Beispiel die Farbe nicht wirklich ändern.. Werde bei Gelegenheit noch ein paar Dinge optimieren, bekomme aber auch immer gerne Feedback!</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flexfractal.zip'>Quellcode als FlashDevelop Projekt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/fraktal-mit-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Entwicklung mit FlashDevelop</title>
		<link>http://www.codeblog.ch/de/2008/04/flex-entwicklung-mit-flashdevelop/</link>
		<comments>http://www.codeblog.ch/de/2008/04/flex-entwicklung-mit-flashdevelop/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 11:15:39 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flashdevelop]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=13</guid>
		<description><![CDATA[Wer SWF Dateien erstellen wollte, war bisher immer relativ stark an Adobe Flash gebunden. Adobe Flash ist noch immer das einzige Werkzeug, das wirklich alle Features von Flash mit einem grafischen Interface zur Verfügung stellt. Es gibt inzwischen einige Tools um für einen speziellen Zweck SWF Dateien zu erstellen, dies beschränkt sich dann aber auf [...]]]></description>
			<content:encoded><![CDATA[<p>Wer SWF Dateien erstellen wollte, war bisher immer relativ stark an Adobe Flash gebunden. Adobe Flash ist noch immer das einzige Werkzeug, das wirklich alle Features von Flash mit einem grafischen Interface zur Verfügung stellt.</p>
<p>Es gibt inzwischen einige Tools um für einen speziellen Zweck SWF Dateien zu erstellen, dies beschränkt sich dann aber auf Bildergalerien, kleine Animationen oder ähnliches.</p>
<p>Als ich vor einigen Tagen das Flex SDK angeschaut habe, bin ich auch auf eine Seite eines Programmes gestossen das meiner Meinung nach zu unbekannt ist. <a href="http://osflash.org/flashdevelop">FlashDevelop</a></p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flashdevelop.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/flashdevelop-458x400.png" alt="" title="flashdevelop" width="458" height="400" class="alignnone size-medium wp-image-14" /></a></p>
<p><span id="more-13"></span></p>
<p>Die Oberfläche präsentiert sich nach dem Start sehr aufgeräumt, vom Aufbau her ganz ähnlich zu Visual Studio. Wir wollen natürlich gleich mit einem Projekt starten. Im Menü &#8220;Project&#8221; wählen wir &#8220;New Project&#8230;&#8221; und erhalten eine Liste mit verschiedenen Typen, Flash, Flex 2.0, Flex 3.0 usw. Wir wollen eine Flex Anwendung entwickeln und verwenden dazu Flex 3.0.</p>
<p>Gleich nachdem das Projekt angelegt wurde, erstellt FlashDevelop eine Datei main.mxml welche so auch gleich ausführbar ist. Wir wollen nun gleich das erstelle File übersetzen und anzeigen lassen. Ein Klick auf den blauen Pfeil (oder F5) &#8211; es erscheint ein Konfiugrationsdialog. Wir haben FlashDevelop das erstemal gestartet und müssen nun noch angeben wo sich das Flex SDK befindet.</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flashdevelop-config.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/flashdevelop-config-475x334.png" alt="" title="flashdevelop-config" width="475" height="334" class="alignnone size-medium wp-image-15" /></a></p>
<p>Wir müssen hier lediglich bei &#8220;Flex SDK Location&#8221; den korrekten Pfad angeben. Und schon ist FlashDevelop fähig unsere MXML Datei zu übersetzen  und anzeigen.</p>
<p>Durch das MDI Docking Interface lassen sich auch zahlreiche Fenster öffnen so dass wir alles was wir wollen im Überblick haben.</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flashdevelop-example.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/flashdevelop-example-475x314.png" alt="" title="flashdevelop-example" width="475" height="314" class="alignnone size-medium wp-image-16" /></a></p>
<p><strong>Fazit</strong></p>
<p>FlashDevelop ist klein schlank, und vorallem sehr aufgeräumt. Für Leute mit Erfahrungen im Bereich Softwareentwicklung, Visual Studio oder ähnlichem, wirkt die Oberfläche sehr übersichtlich. Nett sind auch Kleinigkeiten wie das automatische Anzeigen des Konfigurationdialoges wenn eine Einstellung fehlt. Von einem derart unbekannten Programm hätte ich dies nicht erwartet, auch eine sprechende Fehlermeldung wäre da ganz gut gewesen.</p>
<p>Da der Adobe Flex Builder für meine Spielereien etwas zu teuer ist, wird FlashDevelop ab sofort meine neue Entwicklungsumgebung für Flex werden! cmd.exe ist auf Dauer doch etwas umständlich!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/flex-entwicklung-mit-flashdevelop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datenaustausch mit Flex</title>
		<link>http://www.codeblog.ch/de/2008/04/datenaustausch-mit-flex/</link>
		<comments>http://www.codeblog.ch/de/2008/04/datenaustausch-mit-flex/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 15:34:57 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=9</guid>
		<description><![CDATA[In diesem Beitrag geht es um die Erstellung einer sehr einfachen Applikation, die Daten von einem PHP Script holt und auch wieder zurückgeben kann. Wer noch nie mit Flex gearbeitet hat, sollte vielleicht zuerst diesen Artikel lesen: Einstieg in Adobe Flex. Wie im ersten Artikel arbeiten wir auch hier ohne den Flex Builder &#8211; nur [...]]]></description>
			<content:encoded><![CDATA[<p>In diesem Beitrag geht es um die Erstellung einer sehr einfachen Applikation, die Daten von einem PHP Script holt und auch wieder zurückgeben kann. Wer noch nie mit Flex gearbeitet hat, sollte vielleicht zuerst diesen Artikel lesen: <a href="http://www.codeblog.ch/2008/04/einstieg-in-adobe-flex-3/">Einstieg in Adobe Flex</a>. Wie im ersten Artikel arbeiten wir auch hier ohne den Flex Builder &#8211; nur das kostenlose Flex SDK wird benötigt.</p>
<p><a href='http://www.codeblog.ch/wp-content/uploads/2008/04/flex-php-dataexchange1.png'><img src="http://www.codeblog.ch/wp-content/uploads/2008/04/flex-php-dataexchange1-475x367.png" alt="" title="flex-php-dataexchange1" width="475" height="367" class="alignnone size-medium wp-image-11" /></a></p>
<p><span id="more-9"></span></p>
<p>Wir holen in diesem Fall die Daten von einem PHP Script, theoretisch kann aber auch ASP.NET, JSP, Ruby usw. zum Einsatz kommen. Die Daten die wir anzeigen, werden im XML Format übertragen. Damit dieser Artikel nur zu gross wird, hab ich eine statische XML Struktur in die PHP Datei eingefügt. Der folgende Code zeigt dies. Am Ende des PHP Codes steht auch der Teil, der für das Einfügen von neuen Datenbank-Einträgen verantwortlich ist, aber auch hier kein wirklicher Code, es wird lediglich eine Datei geschrieben:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$xmlData</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;eod
&lt;response&gt;
&lt;data&gt;
&lt;row&gt;
&lt;id&gt;1&lt;/id&gt;
&lt;firstName&gt;Hans&lt;/firstName&gt;
&lt;lastName&gt;Mustermann&lt;/lastName&gt;
&lt;mailAddress&gt;nirgendwo@da.com&lt;/mailAddress&gt;
&lt;/row&gt;
&lt;row&gt;
&lt;id&gt;2&lt;/id&gt;
&lt;firstName&gt;Frida&lt;/firstName&gt;
&lt;lastName&gt;Beispielfrau&lt;/lastName&gt;
&lt;mailAddress&gt;nirwana@heaven.org&lt;/mailAddress&gt;
&lt;/row&gt;
&lt;/data&gt;
&lt;/response&gt;
EOD</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'method'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'getAll'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xmlData</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'method'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'insert'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test.log'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'firstName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mailAddress'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Dies ist schon alles was wir serverseitig benötigen, aber wie gesagt dies ist nur ein stark vereinfachter Code. Es werden Daten weder abgespeichert, noch aus einer Datenbank ausgelesen.</p>
<p>Wir erstellen nun also wieder eine MXML Datei mit einem beliebigen Editor.</p>
<p>Da wird zwei Formulare benötigen, für die Ausgabe der Daten in einer Tabelle, und für die Eingabe von neuen Einträgen. Wir verwenden dafür das sogenannte &#8220;ViewStack&#8221; Control mit dem wir verschieden Controls an einer Stelle platzieren können. Mittels einer Zeile Code können wir ganz einfach das aktive Control bestimmen.</p>
<p>In Zeile 1 steht im Click Ereignis des Buttons ein Code der im untenstehen Viewstack das Canvas Control in den Vordergrund bringt.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Hinzufügen...&quot;</span> click=<span style="color: #ff0000;">&quot;{viewstack.selectedIndex = 1}&quot;</span><span style="color: #66cc66;">/&gt;</span>
...
<span style="color: #66cc66;">&lt;</span>mx:ViewStack id=<span style="color: #ff0000;">&quot;viewstack&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;</span>mx:Panel label=<span style="color: #ff0000;">&quot;Personen&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
   ...
   <span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;</span>mx:Canvas label=<span style="color: #ff0000;">&quot;Neue Person einfügen&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
   ...
   <span style="color: #66cc66;">&lt;/</span>mx:Canvas<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:ViewStack<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Wie im vorigen Artikel verwenden wir den HTTPService um Daten vom Server zu holen bzw. zu speichern.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:HTTPService id=<span style="color: #ff0000;">&quot;httpService&quot;</span>
                <span style="color: #0066CC;">url</span>=<span style="color: #ff0000;">&quot;data.php&quot;</span>
                resultFormat=<span style="color: #ff0000;">&quot;e4x&quot;</span>
                fault=<span style="color: #ff0000;">&quot;Alert.show(event.fault.faultString), 'Error'&quot;</span>
                useProxy=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">/&gt;</span></pre></div></div>

<p>Dieses HTTPService Objekt kann HTTP Anfragen mit der GET und POST Methode schicken bzw. empfangen. Da wir beim Auslesen der Daten kaum Daten übergeben verwenden wir dort die GET Methode:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">httpService.<span style="color: #006600;">method</span> = <span style="color: #ff0000;">&quot;GET&quot;</span>;
httpParams<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'method'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;getAll&quot;</span>;
httpService.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>httpParams<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Beim Abspeichern hingeben kommt die POST Methode zum Einsatz. Der Code ist aber fast identisch:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">httpService.<span style="color: #006600;">method</span> = <span style="color: #ff0000;">&quot;POST&quot;</span>;
httpParams = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;method&quot;</span>:      <span style="color: #ff0000;">&quot;insert&quot;</span>,
              <span style="color: #ff0000;">&quot;firstName&quot;</span>:   inputFirst.<span style="color: #0066CC;">text</span>,
              <span style="color: #ff0000;">&quot;lastName&quot;</span>:    inputLast.<span style="color: #0066CC;">text</span>,
              <span style="color: #ff0000;">&quot;mailAddress&quot;</span>: inputMail.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#125;</span>;
httpService.<span style="color: #006600;">cancel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
httpService.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>httpParams<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Abgesehen von diesem Code benötigen wir ein paar Kleinigkeiten wie zum Beispiel eine Clear-Methode um die Eingabefelder nach der Eingabe zu löschen. Und natürlich einiges an XML Anweisungen um das GUI aufzubauen. Dies sollte aber zu einem grossen Teil selbsterklärend sein, wenn HTML und XML nicht ganz neu sind.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;fetchData()&quot;</span><span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
   <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
   <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">XMLListCollection</span>;
   <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
&nbsp;
   <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> httpParams:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
   <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> xmlData:XMLListCollection;
&nbsp;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
   <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> result:<span style="color: #0066CC;">XML</span> = <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #000000; font-weight: bold;">var</span> xmlList:XMLList = result.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      xmlData = <span style="color: #000000; font-weight: bold;">new</span> XMLListCollection<span style="color: #66cc66;">&#40;</span>xmlList<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertItemHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
      fetchData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> fetchData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
   <span style="color: #66cc66;">&#123;</span>
      httpService.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,insertItemHandler<span style="color: #66cc66;">&#41;</span>;
      httpService.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,resultHandler<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      httpService.<span style="color: #006600;">method</span> = <span style="color: #ff0000;">&quot;GET&quot;</span>;
      httpParams<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'method'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;getAll&quot;</span>;
&nbsp;
      httpService.<span style="color: #006600;">cancel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      httpService.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>httpParams<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
   <span style="color: #66cc66;">&#123;</span>
      httpService.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,resultHandler<span style="color: #66cc66;">&#41;</span>;
      httpService.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,insertItemHandler<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      httpService.<span style="color: #006600;">method</span> = <span style="color: #ff0000;">&quot;POST&quot;</span>;
      httpParams = <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;method&quot;</span>:      <span style="color: #ff0000;">&quot;insert&quot;</span>,
                    <span style="color: #ff0000;">&quot;firstName&quot;</span>:   inputFirst.<span style="color: #0066CC;">text</span>,
                    <span style="color: #ff0000;">&quot;lastName&quot;</span>:    inputLast.<span style="color: #0066CC;">text</span>,
                    <span style="color: #ff0000;">&quot;mailAddress&quot;</span>: inputMail.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#125;</span>;
      httpService.<span style="color: #006600;">cancel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      httpService.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span>httpParams<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      viewstack.<span style="color: #006600;">selectedIndex</span> = <span style="color: #cc66cc;">0</span>;
      clearFields<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clearFields<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
   <span style="color: #66cc66;">&#123;</span>
      inputFirst.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
      inputLast.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
      inputMail.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
   <span style="color: #66cc66;">&#125;</span>
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> cancelInsert<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
   <span style="color: #66cc66;">&#123;</span>
      viewstack.<span style="color: #006600;">selectedIndex</span> = <span style="color: #cc66cc;">0</span>;
      clearFields<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
   <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;</span>mx:HTTPService id=<span style="color: #ff0000;">&quot;httpService&quot;</span>
                   <span style="color: #0066CC;">url</span>=<span style="color: #ff0000;">&quot;data.php&quot;</span>
                   resultFormat=<span style="color: #ff0000;">&quot;e4x&quot;</span>
                   fault=<span style="color: #ff0000;">&quot;Alert.show(event.fault.faultString), 'Error'&quot;</span>
                   useProxy=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
   <span style="color: #66cc66;">&lt;</span>mx:ViewStack id=<span style="color: #ff0000;">&quot;viewstack&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
      <span style="color: #66cc66;">&lt;</span>mx:Panel label=<span style="color: #ff0000;">&quot;Personen&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;</span>mx:DataGrid <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{xmlData}&quot;</span><span style="color: #66cc66;">&gt;</span>
              <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn dataField=<span style="color: #ff0000;">&quot;firstName&quot;</span> headerText=<span style="color: #ff0000;">&quot;Vorname&quot;</span><span style="color: #66cc66;">/&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn dataField=<span style="color: #ff0000;">&quot;lastName&quot;</span> headerText=<span style="color: #ff0000;">&quot;Nachname&quot;</span><span style="color: #66cc66;">/&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn dataField=<span style="color: #ff0000;">&quot;mailAddress&quot;</span> headerText=<span style="color: #ff0000;">&quot;Mail&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;</span>mx:Form<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Neue Person einf&amp;#252;gen&quot;</span><span style="color: #66cc66;">&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Hinzufügen...&quot;</span> click=<span style="color: #ff0000;">&quot;{viewstack.selectedIndex = 1}&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;/</span>mx:Form<span style="color: #66cc66;">&gt;</span>
      <span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span>
      <span style="color: #66cc66;">&lt;</span>mx:Canvas label=<span style="color: #ff0000;">&quot;Neue Person einfügen&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;</span>mx:Form horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#FFFFFF&quot;</span><span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Vorname&quot;</span><span style="color: #66cc66;">&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:TextInput id=<span style="color: #ff0000;">&quot;inputFirst&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Nachname&quot;</span><span style="color: #66cc66;">&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:TextInput id=<span style="color: #ff0000;">&quot;inputLast&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Mail&quot;</span><span style="color: #66cc66;">&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:TextInput id=<span style="color: #ff0000;">&quot;inputMail&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:ControlBar<span style="color: #66cc66;">&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Einfügen&quot;</span> click=<span style="color: #ff0000;">&quot;insert()&quot;</span> <span style="color: #66cc66;">/&gt;</span>
               <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Abbrechen&quot;</span> click=<span style="color: #ff0000;">&quot;cancelInsert()&quot;</span> <span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;/</span>mx:ControlBar<span style="color: #66cc66;">&gt;</span>
         <span style="color: #66cc66;">&lt;/</span>mx:Form<span style="color: #66cc66;">&gt;</span>
      <span style="color: #66cc66;">&lt;/</span>mx:Canvas<span style="color: #66cc66;">&gt;</span>
   <span style="color: #66cc66;">&lt;/</span>mx:ViewStack<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Bei den Sonderzeichen gibt es noch eine Kleinigkeit zu beachten. Wer gerne Umlaute in seinem Flex GUI anzeigen möchte, sollte darauf achten, dass die MXML Datei im UTF-8 Format gespeichert wird. Bei FlashDevelop einfach bei &#8220;File &#8211; Encoding &#8211; UTF-8&#8243; auswählen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/datenaustausch-mit-flex/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Einstieg in Adobe Flex 3</title>
		<link>http://www.codeblog.ch/de/2008/04/einstieg-in-adobe-flex-3/</link>
		<comments>http://www.codeblog.ch/de/2008/04/einstieg-in-adobe-flex-3/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 11:44:14 +0000</pubDate>
		<dc:creator>Remo Laubacher</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.codeblog.ch/?p=5</guid>
		<description><![CDATA[Allgemein Schon länger liest man öfters die drei Buchstaben RIA. Mit diesem, ich nenne es mal, Modewort entstanden auch verschiedene mehr oder weniger neue Technologien. Einige, wie zum Beispiel AJAX basieren eigentlich komplett auf älteren Technologien, anderen wie zum Beispiel Flex verwenden das ebenfalls nicht mehr neue Flash. Bei Flex ist allerdings die Art und [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Allgemein</strong></p>
<p>Schon länger liest man öfters die drei Buchstaben <abbr title="Rich Internet Application">RIA</abbr>. Mit diesem, ich nenne es mal, Modewort entstanden auch verschiedene mehr oder weniger neue Technologien. Einige, wie zum Beispiel <abbr title="Asynchronous JavaScript And XML">AJAX</abbr> basieren eigentlich komplett auf älteren Technologien, anderen wie zum Beispiel Flex verwenden das ebenfalls nicht mehr neue Flash.</p>
<p>Bei Flex ist allerdings die Art und Weise wie man schlussendlich zu einer SWF-Datei kommt stark abweichend von dem was alteingesessene Flash Freunde sich gewohnt sind.</p>
<p><span id="more-5"></span></p>
<p>Bei Adobe gibt es eine schöne Übersicht, über die Adobe RIA Technologien. <a href="http://www.adobe.com/resources/business/rich_internet_apps/" target="_blank">http://www.adobe.com/resources/business/rich_internet_apps/</a></p>
<p>Auf dieser Grafik ist auch zu erkennen, dass das eigentlich Thema dieses Artikels nur ein Framework ist, Adobe aber eigentlich vorsieht, Flex Projekte mit dem Flex Builder zu erstellen. Flex Builder ist ein auf Eclipse basierendes Werkzeug um Flex Anwendungen zu entwickeln. Im Gegensatz zum Flex <abbr title="Software Development Kit">SDK</abbr> aber nicht gratis! Und da ich persönlich immer gerne zuerst die Technologie verstehe, wollte ich von ganz vorne beginnen, also nur mit dem freiverfügbaren Flex SDK.</p>
<p><strong>Die Vorbereitungen</strong></p>
<p>Natürlich benötigen wir das Flex SDK. Dies finden wir zum Beispiel hier: <a href="http://www.adobe.com/go/flex3_sdk" target="_blank">http://www.adobe.com/go/flex3_sdk</a>. Wer will kann auf dieser Seite auch eine 60-Tage Testversion des Flex Builders herunterladen, wir scrollen aber als erstes mal weiter runter und holen uns das Flex SDK.</p>
<p>Das Flex SDK ZIP entpacken, z.B. nach c:\flex</p>
<p>Da wie erwähnt Flash eine der grundlegenden Technologie ist, brauchen wir einen Flash Player. Ich geh aber davon aus, dass dies bereits installiert ist.</p>
<p><strong>Hello World</strong></p>
<p>Wie könnte ich anders als zu Beginn ein kleines Hello World zu schreiben. Bei Flex gibt es zwei Dinge die zu diesem Weg führen. Einerseits gibt es ActionScript welches wir schon von Flash kennen und es gibt das neue MXML welches wie unschwer zu erkennen, eine <abbr title="Xtended Markup Language">XML</abbr> Erweiterung ist. Da ich wenn es um <abbr title="Graphical User Interface">GUI</abbr>s geht ein Freund von XML bin werde ich den ActionScript Teil mal weglassen.</p>
<p>Hier mal ein erstes MXML Beispiel ohne Worte:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Hello from CodeBlog.ch!&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Abspeichern unter HelloWorld.mxml.</p>
<p>Anschliessend öffnen wir ein CMD-Fenster und lassen uns eine SWF Datei erstellen, indem wir mit dem Befehl mxmlc die vorher erstellte Datei übergeben:</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/04/flex-hello-world.png"><img class="alignnone size-medium wp-image-6" title="flex-hello-world" src="http://www.codeblog.ch/wp-content/uploads/2008/04/flex-hello-world-300x67.png" alt="" width="300" height="67" /></a></p>
<p>Und schon haben wir unsere erste SWF Datei. Die passende <abbr title="HyperText Markup Language">HTML</abbr> Datei schreiben, per Doppelklick starten (geht nicht immer) oder einfach wieder löschen.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/04/hello-world.png"><img class="alignnone size-medium wp-image-8" title="hello-world" src="http://www.codeblog.ch/wp-content/uploads/2008/04/hello-world-300x180.png" alt="" width="300" height="180" /></a></p>
<p><strong>Datenaustausch per <abr title="HyperText Transport Protocoll">HTTP</abbr></strong></p>
<p>Nach der anspruchsvollen HelloWorld Aufgabe wollen wir Daten von einem Webserver auslesen. Dazu hab ich eine PHP Datei geschrieben die den Wert des Parameters &#8220;input&#8221; ausgibt (echo $_REQUEST['input']).</p>
<p>Flex stellt uns für zahlreiche Dinge wie HTTP oder Webservice Anfragen Klassen zur Verfügung.</p>
<p>Wir beginnen gleich wieder mit dem Code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #808080; font-style: italic;">&lt;!--[CDATA[</span>
<span style="color: #808080; font-style: italic;">   import mx.controls.Alert;</span>
<span style="color: #808080; font-style: italic;">   import mx.rpc.events.ResultEvent;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">   private function sendHttpRequest(event:ResultEvent):void</span>
<span style="color: #808080; font-style: italic;">   {</span>
<span style="color: #808080; font-style: italic;">      Alert.show(event.result.toString(), &quot;Content&quot;);</span>
<span style="color: #808080; font-style: italic;">   }</span>
<span style="color: #808080; font-style: italic;">   ]]--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HTTPService</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;http&quot;</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://www.codeblog.ch/flex/echo.php&quot;</span> <span style="color: #000066;">showBusyCursor</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">result</span>=<span style="color: #ff0000;">&quot;sendHttpRequest(event)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Button</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;httpRequest&quot;</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;CodeBlog HTTP Request&quot;</span> <span style="color: #000066;">click</span>=<span style="color: #ff0000;">&quot;http.send({input: 'Hello CodeBlog!'});&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Wir haben nun eine Script Sektion (mx:Script) mit einem CDATA Block. Auch hier sieht man wieder die Ähnlichkeit zu XML. Wir definieren lediglich eine Funktion &#8220;sendHttpRequest&#8221;, die die Anfrage ausführt und das Ergebnis in einer Dialog Box ausgibt.</p>
<p>Mit mx:HTTPService definieren wir die Parameter für unsere HTTP Anfrage. Neben der Adresse geben wir hier lediglich an dass wir gerne einen &#8220;Busy-Cursor&#8221; hätten. Dann noch ein Button der die Funktion startet und fertig! Damit können wir bereits HTML Daten auslesen.</p>
<p><a href="http://www.codeblog.ch/wp-content/uploads/2008/04/http-hello-world.png"><img class="alignnone size-medium wp-image-7" title="http-hello-world" src="http://www.codeblog.ch/wp-content/uploads/2008/04/http-hello-world-300x229.png" alt="" width="300" height="229" /></a></p>
<p>Kleiner Hinweis am Rande, wer Daten von &#8220;fremden Servern&#8221; auslesen will, sollte sich bezüglich crossdomain.xml schlau machen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codeblog.ch/de/2008/04/einstieg-in-adobe-flex-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

