intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

adobe flash cs5 on demand part 62

Chia sẻ: Mr Yukogaru | Ngày: | Loại File: PDF | Số trang:6

80
lượt xem
9
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Kiểm soát dữ liệu Có một số cách quan trọng để kiểm soát dữ liệu trong ActionScript 3.0. Chúng bao gồm các mảng, chia sẻ các đối tượng và XML. Mảng là phương pháp đầu tiên bạn có khả năng sử dụng trong mã ActionScript của bạn. Vai trò của một mảng là tạo ra một danh sách các kiểu dữ liệu trong mã của bạn. Ví dụ, bạn có thể muốn danh sách các màu đỏ, xanh lá cây, xanh da trời và màu cam. ...

Chủ đề:
Lưu

Nội dung Text: adobe flash cs5 on demand part 62

  1. Controlling Data There are several key ways to control data in When you are counting the number of ActionScript 3.0. They include Arrays, Shared values in an Array you have to remember Objects and XML. An Array is the first method that Arrays always start with 0. For instance, you are likely to use in your ActionScript if you have five items in an array and tell the code. The role of an Array is to create a list of array to pull item 1, it will pull the second data types in your code. For example, you item. This is because the first item has the may want to list the colors red, green, blue registered value of 0. and orange. To do this you need to define a If you are developing an AIR solution you new variable with the data type of Array: can take advantage of the SQL database built var colorArray:Array = new Array("red", "green", right into AIR. The SQL database comes with "blue", "orange"); support for the creation of tables, stored pro- cedures and SQL statements. You can see in this script that a set of four items have been inserted into the Array. You can access the data in the Array with the fol- Using Flash Cookies lowing trace statement: The Flash Player can also store data locally in trace (colorArray); very much the same way that a cookie can be The “push” property will allow you to add a stored in a Web browser. Flash does not call new item into your array: this cookies but Shared Objects. An example of Share Object ActionScript 3.0 is: colorArray.push("purple"); var mySO:SharedObject = To remove the last item of an Array you can SharedObject.getLocal("myFlashCookie"); use the Pop property. mySO.data.now = new Date().time; colorArray.pop(); trace(mySO.data.now); What you will find is that Arrays are great for manage simple lists. Additional properties The Share Object is declared and given a allow you to remove specific values, to count name where it will be stored on the local the number of values you have and to sort computer. You can now effectively target data your lists. For more complex data you will to this space that can be accessed if this com- want to leverage the Local Data Storage or puter comes back to this page at a later date. XML. 380 Chapter 15
  2. Manipulating XML with E4X Flash has supported XML in one fashion or xmlLoader.addEventListener another since Flash 5. Have you worked with (Event.COMPLETE,onXMLLoaded); XML in ActionScript 2.0? It’s not pretty. To our xmlLoader.load relief, ActionScript 3.0 now supports the (new URLRequest("colors.xml")); ECMA XML standard called E4X. You can now more easily step through your XML docu- 6 At this point you have loaded the XML ments. You can also change the value of items successfully into Flash. You can test this into an XML document. What this means is by adding the following function to trace the contents of the XML document into that you can load an XML document and then your OutPut window. modify the content. For instance, you can change Yellow to Blue. function onXMLLoaded(e:Event):void{ myXml = new XML(e.target.data); Import an XML Document as a Data Type trace(myXml); 1 Before you can import an XML document, you need to create one. You } can use the following code and save it as an XML document with the name colors.xml. Orange Red Yellow 2 Click the File menu, click New, click ActionScript 3.0, and then click OK. 7 You can now easily pull out a specific 3 Click the File menu, and then click Save value. For instance, add the following to to save the FLA file to the same folder as the onXMLLoaded function to extract the the XML document. third value in the XML file: 4 The first step is to create a new object to trace(myXml..color[2]); manage the XML: The double dots after the variable myXML var myXml:XML; allows you to step to the second value of your 5 The next step is to create a new XML document. All of this is so much easier URLLoader file that will load the XML to accomplish with E4X than with file: ActionScript 2.0. var xmlLoader = new URLLoader(); Chapter 15 Working with ActionScript 3.0 381
  3. Using Regular Expressions Patterns are everywhere as you develop your Next, create a new Regular Expression that is code. This is clearly seen with the use of looking for a pattern structure in your email: Regular Expressions, a method for describing var emailRegExp:RegExp = /^([a-zA-Z0-9_-]+)@([a- the pattern of data you are looking to use. zA-Z0-9.-]+)\.([a-zA-Z]{2,4})$/i; Using Regular Expressions you can now eas- ily format form fields to correctly capture The pattern is looking for a combination of date, ZIP or Credit Card numbers. alpha-numerical-special character formats separated by an “@” sign and suffix “ Add .” To validate data meets a simple pattern you the following trace statement to see whether need to create a string variable: or not the pattern works: var myColor = "Orange"; trace( "Is this email valid? " + emailRegExp.test( Now create a new regular expression that is email ) ) looking for a simple pattern. In this instance, Test the movie to view the following response the pattern is that the myColor string value in the Output panel: must start with an “O” . Is this email valid? True var colorRegExp:RegExp = /O/; Change the email address to just “Matthew You can write a trace script to test your David” a pattern that does not match the movie: Regular Expression. When you test the movie trace( colorRegExp.test( myColor ) ); you will see that the Regular Expression returns a false response. The value in the Output panel is True. You can also get great information on how to Let’s extend what you can do with Regular structure regular expressions at: Expressions by adding a pattern that looks for http://www.regular-expressions.info. an email address. Start by adding a new email string with a valid email address: var email:String = "mdavid@matthewdavid.ws"; 382 Chapter 15
  4. Controlling Text In many ways you do not need to work on the private function configuretext():void Stage at all when using ActionScript 3.0. All { visual objects can be programmatically cre- ated. The easiest way to see this is in using myTextField = new TextField(); the Text object to create dynamic text fields on myTextField.y = 200; the Stage. myTextField.x = 100; 8 A textFormat object is used to format the Create a Dynamic Text Field visual properties of the text. For instance, 1 Click the File menu, click New, click the following textFormat object sets the ActionScript 3.0, and then click OK. font to “_sans” the color black and font , size 15: 2 Open the Properties panel. 3 var format:TextFormat = new TextFormat(); Click the Edit Class Definition button (small pencil icon) in the Properties format.font = "_sans"; inspector, enter a new class with the format.color = 0x000000; name text, and then click OK. format.size = 15; A new ActionScript file named text.as opens. myTextField.defaultTextFormat = format; 4 addChild(myTextField); Add the libraries to be imported into your file: 9 The final two public functions tie the text string to the new formatted text field: import flash.display.Sprite; public function text() import flash.text.TextField; { import flash.text.TextFieldAutoSize; configuretext(); import flash.text.TextFormat; setValueOfTextField(someText); 5 Insert a private variable that will be used } to define the dynamic text: public function setValueOfTextField private var myTextField:TextField; (str:String):void 6 The following creates a basic string you { can insert into your texftfield: myTextField.text = str; private var someText:String = "Hello world."; } A private function is used to define the 10 Click the Control menu, point to Test physical position of the textfield on the Movie, and then click Test to display a screen. text string added to your screen. 7 Declare the text field as a new object, Creating a dynamic text field on the Stage and then use the X and Y properties to with ActionScript allows you more control place the text on the screen: over the text on the Stage than using tradi- tional methods. Chapter 15 Working with ActionScript 3.0 383
  5. Drawing with the Shape Class As with the text object, you can create images 2 The following ActionScript formats the dynamically in ActionScript 3.0. There are sev- size, fill/outline color, and position of the eral different types of image you can create Sprite: that include traditional Movie Clips and Graphics. You can now also create a new type myFirstSprite.graphics.lineStyle(3,0xFF6600); of image called a Sprite. Essentially, a Sprite myFirstSprite.graphics.beginFill(0xFF0000); is the same as a Movie Clip with the excep- myFirstSprite.graphics.drawRect(0,0,100,100); tion that it does not contain timeline function- ality. Sprite’s can be created by invoking the myFirstSprite.graphics.endFill(); new Sprite Object Class and then adding 3 Click the Control menu, point to Test properties to the object. Movie, and then click Test to view the rectangle on the screen. 4 The following ActionScript applies a fade in transition effect to your new Sprite. myFirstSprite.addEventListener (Event.ENTER_FRAME, fadeInSprite); myFirstSprite.alpha = 0; function fadeInSprite(event:Event) { myFirstSprite.alpha += 0.01; if(myFirstSprite.alpha >= 1) { myFirstSprite.removeEventListener (Event.ENTER_FRAME, fadeInSprite); } } Add a Square Shaped Sprite to the Stage You can do a lot with ActionScript constructed 1 Add the following ActionScript to create images. Working with the all the different a new Sprite with the name objects available to you in ActionScript 3.0 myFirstSprite. you have almost no limits to what you can var myFirstSprite:Sprite = new Sprite(); create using Flash. addChild(myFirstSprite); 384 Chapter 15
  6. Developing iPhone Apps 16 Introduction What You’ll Do Apple has this device called an iPhone. Have your heard of Become an Apple Certified Developer it? Of course you have. There is even a good chance you have an iPhone. While the iPhone itself is an amazing piece of Register an iPhone and other Apple technology, it is the software that makes the iPhone really Testing Devices great. The challenge in developing applications for the iPhone is Create App’s ID that you need to know how to develop using Apple’s Cocoa Create a Developer’s Provisioning Touch framework and the programming language Objective Profiles C. One of the most interesting and talked about features in Flash CS5 is Adobe’s inclusion of a tool that converts your Create and Publish an iPhone App Flash movies to files that will run on any iPhone OS device without needing to know Objective C. You just need to apply Control the Accelerometer the Flash and ActionScript knowledge you already have. A new tool in Flash CS5, called the iPhone Packager, converts Save Images to the Camera Roll 16 files into valid iPhone applications. Understand the Limitations of Flash Before you can create an iPhone App there are several activities you need to complete so you can develop in Flash Identify Devices to Deploy an Ad CS5. They are (1) Become a Certified Apple Developer, (2) Hoc App Create a Development and Developer P12 certificate, and (3) Register your development iPhone with Apple. Create an Ad Hoc Distribution Profile In this chapter, you’ll get an overview for how to start Package an Ad Hoc App developing for the iPhone using Flash CS5 including deploy- ing an App to the iTunes App Store. Use iTunes Connect to Publish an App Use Screen Orientation in an App Use Geolocation in an App Use Multitouch in an App 385
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2