Loading JPGs Dynamically
Số trang: 10
Loại file: pdf
Dung lượng: 24.64 KB
Lượt xem: 10
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Loading JPGs động các Bây giờ bạn đã học được làm thế nào để tải một bộ phim bên ngoài vào một dự án, quá trình tự động tải một JPG nên dễ nó gần giống như của tải một SWF bên ngoài. Như thể hiện trong tập thể dục trước đó, các loadMovie () tải một hành động SWF bên ngoài vào mục tiêu. Bạn sẽ sử dụng cùng một hành động để nạp một bên ngoài JPG, nhưng với twist một.
Nội dung trích xuất từ tài liệu:
Loading JPGs Dynamically < Day Day Up >Loading JPGs DynamicallyNow that youve learned how to load an external movie into a project, the process ofdynamically loading a JPG should be easy—its almost identical to that of loading anexternal SWF. As demonstrated in the preceding exercise, the loadMovie() action loadsan external SWF into a target. Youll use the same action to load an external JPG—butwith a twist. Look at the following syntax:loadMovie(myBitmap.jpg, myClip_mc);This loadMovie() action identifies a JPG as the external asset to load. Here,myBitmap.jpg is loaded into the myClip_mc target. After a JPG is loaded into a movie inthis fashion, Flash sees it as a movie clip instance, which means that you can control itvia ActionScript—rotating, resizing, or making it transparent as with any other clip.In this exercise, well build slideshow functionality into our project to demonstrate howwe can load JPGs into a target on an as-needed basis. 1. Open virtualaquarium2.fla. Well continue working with this file from the preceding exercise. Note the empty movie clip instance on the Placeholder layer (the small white circle in the panel graphics upper-left corner). Called placeholder_mc, this is the movie clip instance into which our external JPGs will be loaded. Also note the text field with the name title_txt, at the top of the panel; well use that in our exercise as well. Before we begin scripting, lets review the contents of the directory containing our externally loaded assets.2. Using your operating systems directory-exploring application, navigate to the Lesson18/Assets directory and locate the image files named image0.jpg, image1.jpg, and image2.jpg. Each of these images is 378 pixels wide by 178 pixels high—the size at which the image will be loaded into the receiving movie. After the images are loaded, however, Flash will recognize them as movie clip instances and can thus resize and transform them in any number of ways, as well demonstrate in the next exercise. NOTE Only standard JPG files are supported. Progressive JPG files are not supported.3. Return to Flash. With the Actions panel open, select Frame 1 of the Actions layer and add the following line of script just below the backgrounds array from the preceding exercise:4.5.6. var slides:Array = new Array([Shark, image0.jpg], [Jellyfish,)image1.jpg],7.8. [Seahorse, image2.jpg]);9. This step creates a new two-dimensional array named slides. As you learned in Lesson 6, Creating and Manipulating Data, this is an array in which each element contains more than one item. The first part of each element is simply a string description of the image; the second parameter represents the directory path to that image. Now lets create a function to load these images into our project, with the functionality of a slideshow.4. Add the following script just below the randomBackground() function call:5.6. var currentSlide:Number;7.8. function changeSlide(number:Number){9.10. if (number >= 0 && number < slides.length){11.12. currentSlide = number;13.14. title_txt.text = slides[number][0];15.16. loadMovie (slides[number][1], placeholder_mc);17.18. }19.20. }21.The first line creates a variable named currentSlide, which will track the currentlyvisible slide. This variable is created outside the function because it needs to existas long as the application is running. Upcoming steps will discuss how thisvariable is used.The next part of the script creates a function named changeSlide(). Lets look athow this function works.Notice that the function is passed a parameter named number—a numerical valuethat the function will use to determine which image to load. The if statement at thebeginning of the function definition dictates that the function executes only when anumber within a certain range is passed to the function. The lower end of thisrange is 0, and the upper end depends on the number of elements in the slidesarray. Thus, the if statement basically states that if number is greater than or equalto 0 and less than the length of the slides array (which is 3 because the arraycontains three elements), the actions in the function should be executed. Underthese circumstances, the function executes only if number is 0, 1, or 2. (In amoment, youll begin to understand why weve set up the function this way.)The first action in the function sets the value of currentSlide to the value of thenumber parameter passed to the function. This variables value will be used a bitlater, when executing actions on our two arrow buttons.The next line in our script sets the value of the text field title_txt to the value ofslides[number][0]. The last line in the function uses a loadMovie() action to loadone of our external JPG images into the instance named placeholder_mc, which ison the root timeline. To make sense of this function, lets look at a couple ofscenarios:If the value 1 is passed to this function, the if statement determines that to be anacceptable value, and the actions in the function are executed—in which case,theyre evaluated as follows:currentSlide = 1;title_txt.text = slides[1][0];loadMovie (slides[1][1], placeholder_mc);Because the last two actions in the function reference elements in the slides array,you can further break down those actions:currentSlide = 1;title_txt.text = Jellyfish;loadMovie (image1.jpg, placeholder_mc);The result is that image1.jpg is loaded into the instance named placeholder_mcand the text string Jellyfish appears above the panel in the title_txt text field. Lets consider one more scenario. If the value 3 is passed, the if statement prevents the function from executing—and prevents our project f ...
Nội dung trích xuất từ tài liệu:
Loading JPGs Dynamically < Day Day Up >Loading JPGs DynamicallyNow that youve learned how to load an external movie into a project, the process ofdynamically loading a JPG should be easy—its almost identical to that of loading anexternal SWF. As demonstrated in the preceding exercise, the loadMovie() action loadsan external SWF into a target. Youll use the same action to load an external JPG—butwith a twist. Look at the following syntax:loadMovie(myBitmap.jpg, myClip_mc);This loadMovie() action identifies a JPG as the external asset to load. Here,myBitmap.jpg is loaded into the myClip_mc target. After a JPG is loaded into a movie inthis fashion, Flash sees it as a movie clip instance, which means that you can control itvia ActionScript—rotating, resizing, or making it transparent as with any other clip.In this exercise, well build slideshow functionality into our project to demonstrate howwe can load JPGs into a target on an as-needed basis. 1. Open virtualaquarium2.fla. Well continue working with this file from the preceding exercise. Note the empty movie clip instance on the Placeholder layer (the small white circle in the panel graphics upper-left corner). Called placeholder_mc, this is the movie clip instance into which our external JPGs will be loaded. Also note the text field with the name title_txt, at the top of the panel; well use that in our exercise as well. Before we begin scripting, lets review the contents of the directory containing our externally loaded assets.2. Using your operating systems directory-exploring application, navigate to the Lesson18/Assets directory and locate the image files named image0.jpg, image1.jpg, and image2.jpg. Each of these images is 378 pixels wide by 178 pixels high—the size at which the image will be loaded into the receiving movie. After the images are loaded, however, Flash will recognize them as movie clip instances and can thus resize and transform them in any number of ways, as well demonstrate in the next exercise. NOTE Only standard JPG files are supported. Progressive JPG files are not supported.3. Return to Flash. With the Actions panel open, select Frame 1 of the Actions layer and add the following line of script just below the backgrounds array from the preceding exercise:4.5.6. var slides:Array = new Array([Shark, image0.jpg], [Jellyfish,)image1.jpg],7.8. [Seahorse, image2.jpg]);9. This step creates a new two-dimensional array named slides. As you learned in Lesson 6, Creating and Manipulating Data, this is an array in which each element contains more than one item. The first part of each element is simply a string description of the image; the second parameter represents the directory path to that image. Now lets create a function to load these images into our project, with the functionality of a slideshow.4. Add the following script just below the randomBackground() function call:5.6. var currentSlide:Number;7.8. function changeSlide(number:Number){9.10. if (number >= 0 && number < slides.length){11.12. currentSlide = number;13.14. title_txt.text = slides[number][0];15.16. loadMovie (slides[number][1], placeholder_mc);17.18. }19.20. }21.The first line creates a variable named currentSlide, which will track the currentlyvisible slide. This variable is created outside the function because it needs to existas long as the application is running. Upcoming steps will discuss how thisvariable is used.The next part of the script creates a function named changeSlide(). Lets look athow this function works.Notice that the function is passed a parameter named number—a numerical valuethat the function will use to determine which image to load. The if statement at thebeginning of the function definition dictates that the function executes only when anumber within a certain range is passed to the function. The lower end of thisrange is 0, and the upper end depends on the number of elements in the slidesarray. Thus, the if statement basically states that if number is greater than or equalto 0 and less than the length of the slides array (which is 3 because the arraycontains three elements), the actions in the function should be executed. Underthese circumstances, the function executes only if number is 0, 1, or 2. (In amoment, youll begin to understand why weve set up the function this way.)The first action in the function sets the value of currentSlide to the value of thenumber parameter passed to the function. This variables value will be used a bitlater, when executing actions on our two arrow buttons.The next line in our script sets the value of the text field title_txt to the value ofslides[number][0]. The last line in the function uses a loadMovie() action to loadone of our external JPG images into the instance named placeholder_mc, which ison the root timeline. To make sense of this function, lets look at a couple ofscenarios:If the value 1 is passed to this function, the if statement determines that to be anacceptable value, and the actions in the function are executed—in which case,theyre evaluated as follows:currentSlide = 1;title_txt.text = slides[1][0];loadMovie (slides[1][1], placeholder_mc);Because the last two actions in the function reference elements in the slides array,you can further break down those actions:currentSlide = 1;title_txt.text = Jellyfish;loadMovie (image1.jpg, placeholder_mc);The result is that image1.jpg is loaded into the instance named placeholder_mcand the text string Jellyfish appears above the panel in the title_txt text field. Lets consider one more scenario. If the value 3 is passed, the if statement prevents the function from executing—and prevents our project f ...
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLGợi ý tài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 267 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 252 1 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 248 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 246 0 0 -
47 trang 240 3 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 235 0 0 -
80 trang 221 0 0
-
122 trang 215 0 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 214 0 0 -
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 204 0 0