การนำโปรเจ็คแอปพลิเคชั่นใน Flex Builder 3 ไปใช้งานใน Flash Builder 4 by Ziah
Feb1
Flash Builder 4 ในปัจจุบันนั้นค่อนข้างรองรับแอปพลิเคชั่นจากโปรเจ็คที่สร้างใน Flex Builder 3 แล้ว เพียงเรา import โฟลเดอร์โปรเจ็คนั้นๆเข้ามาและเลือกใช้ Flex SDK 4 โดยถ้าเรายังต้องการใช้ Skin halo แบบเดิมกับที่ใช้ใน Flex 3 แล้ว ก็จะมีการเปลี่ยนแปลงเพียงเล็กๆน้อยๆดังนี้
เปลี่ยน namespace ของแอปพลิเคชั่น และเพิ่ม namespace ให้กับ stylesheet
สำหรับแอปพลิเคชั่น มีการแก้ไขดังนี้
Flex 3:
xmlns:mx=”http://www.adobe.com/2006/mxml”Flex 4:
xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:mx=”library://ns.adobe.com/flex/mx”
xmlns:s=”library://ns.adobe.com/flex/spark”
แก้ไข namespace mx เป็น fx
Flex 3:
<mx:Script>
</mx:Script>
<mx:Binding>
</mx:Binding>
<mx:Metadata>
</mx:Metadata>
Flex 4:
<fx:Script>
</fx:Script>
<fx:Binding>
</fx:Binding>
<fx:Metadata>
</fx:Metadata>
และเพิ่ม namespace ให้กับ Stylesheet โดยการเพิ่มโค้ดดังนี้
@namespace “library://ns.adobe.com/flex/mx“;
@namespace s “library://ns.adobe.com/flex/spark“;
จากนั้นก็กำหนด Style
Button{fontSize:18;}
s|Button{fontSize:18;}
เพิ่มแท็ก Declarations ให้กับ Component ที่ไม่เกี่ยวกับการแสดงผล
คอมโพเนนท์ต่างๆที่ไม่เกี่ยวข้องกับการแสดงผลเราจะนำแท็กของมันซ้อนไว้ในแท็ก Declarations ดังนี้
<fx:Declarations>
</fx:Declarations>
ตัวอย่างเช่น
<fx:Declarations>
<mx:StringValidator id=”v1″ source=”{input1}” property=”text” minLength=”24″/>
</fx:Declarations>
แก้ไข States
States ใน Flex 3 จะมีลักษณะดังนี้
Flex 3:
<mx:State name=“loading”>
<mx:AddChild relativeTo=“{myBox}”>
<mx:Text textAlign=“center” text=“Loading…” selectable=“false” />
</mx:AddChild>
…
<mx:VBox id=“myBox”>
</mx:VBox>
แก้ไขเป็น Flex 4 ดังนี้
Flex 4:
<mx:State name=“loading”>
…
<mx:VBox id=“myBox”>
<mx:Text textAlign=“center” text=“Loading…” selectable=“false”
visible=“false” includeInLayout=“false”
visible.loading=“true” includeInLayout.loading=“true”
/>
</mx:VBox>
ในครั้งหน้าจะมาอธิบายถึงการแปลง mx เป็น s หรือ เปลี่ยนสกินจาก Halo เป็น Spark กันนะครับ
credits http://www.learnosity.com/techblog/index.cfm/2010/3/21/Flex-3-to-Flex-4-Migration-Howto
Enjoy this article?
Consider subscribing to our RSS feed!