Flash Builder 4 and Flex 4 Bible- P4
Số trang: 50
Loại file: pdf
Dung lượng: 1.08 MB
Lượt xem: 18
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Flash Builder 4 and Flex 4 Bible- P4: When Macromedia first released Flash MX in 2002, the product was branded as the newway to build Rich Internet Applications (known by the acronym RIA). The term wasinvented at Macromedia to describe a new class of applications that would offer thebenefits of being connected to the Internet, including access to various types of Web-based services,but would solve many of the nagging issues that had been inherent in browser-based applicationssince the mid-1990s....
Nội dung trích xuất từ tài liệu:
Flash Builder 4 and Flex 4 Bible- P4 Chapter 4: Understanding the Anatomy of a Flex Application Any code in the external file is compiled as part of the MXML file and the ActionScript class it rep- resents but is executed after objects declared in MXML are instantiated so you can access these objects in your ActionScript code. Because the external file isn’t in XML format, you don’t need to embed the element or the CDATA block inside the file to protect the code. Follow these steps to create an external ActionScript file: 1. Choose File ➪ New ➪ ActionScript File from the Flash Builder menu. (Don’t select ActionScript Class — that’s a different sort of file I’ll describe in a later chapter.) 2. In the New ActionScript File dialog box, select the folder in which you want to cre- ate the file. External ActionScript files can go anywhere in the project source-code root folder, because you’ll explicitly refer to the file’s location when you link to it from an MXML file. I usually place the file in the same folder as the MXML file it’s linked to. 3. Enter the name of the file. It should have a file extension of .as, but the rest of the file- name is up to you. For an application named HelloWorld.mxml, the matching exter- nal ActionScript file would be helloWorld.as. 4. Click Finish to create the file.NoteNotice that in this usage, the external ActionScript filename starts with a lowercase character. This doesn’thave any technical effect on the code, but it’s a way of indicating that it’s a simple file containing ActionScriptcode, as opposed to an ActionScript class (which, by object-oriented programming conventions, has an initialuppercase character). n After the file has been created, you link to it from the MXML file with the element and add a source property pointing to the external file. The application in Listing 4.2 embeds its ActionScript code in an tag set.CautionAny particular element can contain nested ActionScript or use the source property to link toan external ActionScript file, but it cannot do both at the same time. You can, however, have as many declarations in a single MXML file as you need. n LISTING 4.2 An MXML application with nested ActionScript Part I: Flex Fundamentals LISTING 4.2 (continued) [Bindable] private var currentResult:Number=0; [Bindable] private var currentInput:String=””; private function calculateHandler(event:Event):void { currentResult += Number(currentInput); currentInput=””; } private function selectHandler(event:TextEvent):void { currentInput += event.text; } ]]> On the WebThe code in Listing 4.2 is available in the Web site files in the chapter04 project folder asCalculatorWithScript.mxml. n Listing 4.3 shows the same application after the ActionScript has been moved to an external file. LISTING 4.3 MXML application Calculator.mxml with linked ActionScript file Chapter 4: Understanding the Anatomy of a Flex Application xmlns:s=”library://ns.adobe.com/flex/spark” xmlns:mx=”library://ns.adobe.com/flex/mx” xmlns:components=”components.*”> On the WebThe code in Listing 4.3 is available in the Web site files in the chapter04 project folder as Calculator.mxml. n You have just as much code to manage, but the XML markup is cleaner and easier to read. And, as shown in Listing 4.4, the ActionScript file now contains only the scripting code: LISTING 4.4 External ActionScript file calculator.as //ActionScript code for Calculator.mxml [Bindable] private var currentResult:Number=0; [Bindable] private var currentInput:String=””; private function calculateHandler(event:Event):void { currentResult += Number(currentInput); currentInput=””; } private function selectHandler(event:TextEvent):void { currentInput += event.text; } 123Part I: Flex FundamentalsOn the WebThe code in Listing 4.4 is available in the Web site files in the chapter04 project’s src folder ascalculator.as. n Managing ActionScript code with Flash Builder Whether you’ ...
Nội dung trích xuất từ tài liệu:
Flash Builder 4 and Flex 4 Bible- P4 Chapter 4: Understanding the Anatomy of a Flex Application Any code in the external file is compiled as part of the MXML file and the ActionScript class it rep- resents but is executed after objects declared in MXML are instantiated so you can access these objects in your ActionScript code. Because the external file isn’t in XML format, you don’t need to embed the element or the CDATA block inside the file to protect the code. Follow these steps to create an external ActionScript file: 1. Choose File ➪ New ➪ ActionScript File from the Flash Builder menu. (Don’t select ActionScript Class — that’s a different sort of file I’ll describe in a later chapter.) 2. In the New ActionScript File dialog box, select the folder in which you want to cre- ate the file. External ActionScript files can go anywhere in the project source-code root folder, because you’ll explicitly refer to the file’s location when you link to it from an MXML file. I usually place the file in the same folder as the MXML file it’s linked to. 3. Enter the name of the file. It should have a file extension of .as, but the rest of the file- name is up to you. For an application named HelloWorld.mxml, the matching exter- nal ActionScript file would be helloWorld.as. 4. Click Finish to create the file.NoteNotice that in this usage, the external ActionScript filename starts with a lowercase character. This doesn’thave any technical effect on the code, but it’s a way of indicating that it’s a simple file containing ActionScriptcode, as opposed to an ActionScript class (which, by object-oriented programming conventions, has an initialuppercase character). n After the file has been created, you link to it from the MXML file with the element and add a source property pointing to the external file. The application in Listing 4.2 embeds its ActionScript code in an tag set.CautionAny particular element can contain nested ActionScript or use the source property to link toan external ActionScript file, but it cannot do both at the same time. You can, however, have as many declarations in a single MXML file as you need. n LISTING 4.2 An MXML application with nested ActionScript Part I: Flex Fundamentals LISTING 4.2 (continued) [Bindable] private var currentResult:Number=0; [Bindable] private var currentInput:String=””; private function calculateHandler(event:Event):void { currentResult += Number(currentInput); currentInput=””; } private function selectHandler(event:TextEvent):void { currentInput += event.text; } ]]> On the WebThe code in Listing 4.2 is available in the Web site files in the chapter04 project folder asCalculatorWithScript.mxml. n Listing 4.3 shows the same application after the ActionScript has been moved to an external file. LISTING 4.3 MXML application Calculator.mxml with linked ActionScript file Chapter 4: Understanding the Anatomy of a Flex Application xmlns:s=”library://ns.adobe.com/flex/spark” xmlns:mx=”library://ns.adobe.com/flex/mx” xmlns:components=”components.*”> On the WebThe code in Listing 4.3 is available in the Web site files in the chapter04 project folder as Calculator.mxml. n You have just as much code to manage, but the XML markup is cleaner and easier to read. And, as shown in Listing 4.4, the ActionScript file now contains only the scripting code: LISTING 4.4 External ActionScript file calculator.as //ActionScript code for Calculator.mxml [Bindable] private var currentResult:Number=0; [Bindable] private var currentInput:String=””; private function calculateHandler(event:Event):void { currentResult += Number(currentInput); currentInput=””; } private function selectHandler(event:TextEvent):void { currentInput += event.text; } 123Part I: Flex FundamentalsOn the WebThe code in Listing 4.4 is available in the Web site files in the chapter04 project’s src folder ascalculator.as. n Managing ActionScript code with Flash Builder Whether you’ ...
Tìm kiếm theo từ khóa liên quan:
thiết kế web giáo trình flash cơ bản kỹ năng cắt html photoshop căn bản giáo trình CS3Gợi ý tài liệu liên quan:
-
Báo cáo thực tập: Đề tài thiết kế Web
77 trang 568 2 0 -
Đề thi thực hành môn Thiết kế Web - Trường Cao đẳng nghề Vĩnh Phúc
3 trang 267 2 0 -
MỘT SỐ ĐIỂM CẦN CHÚ Ý KHI THIẾT KẾ WEB
5 trang 113 0 0 -
GIÁO TRÌNH LẬP TRÌNH WEB_PHẦN 2_BÀI 3
3 trang 103 0 0 -
Giáo trình Nhập môn thiết kế website
58 trang 83 0 0 -
Tài liệu giảng dạy Thiết kế giao diện Web - Trường CĐ Kinh tế - Kỹ thuật Vinatex TP. HCM
88 trang 72 0 0 -
81 trang 68 0 0
-
112 trang 64 0 0
-
Hướng dân sử dụng Navicat để Create , Backup , Restore Database
7 trang 63 0 0 -
Giáo trình môn Kỹ thuật vi điều khiển: Thiết kế web và vi điều khiển - Chương 2
39 trang 59 0 0