Defining a Boundary
Số trang: 5
Loại file: pdf
Dung lượng: 22.54 KB
Lượt xem: 3
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:
Chúng tôi xác định một ranh giới contend với ranh giới mỗi ngày. Mặc dù ranh giới có thể mất nhiều hình thức, thể chất, tài chính, tâm thần, cuối cùng họ không có gì hơn một dấu hiệu của một giới hạn
Nội dung trích xuất từ tài liệu:
Defining a Boundary < Day Day Up >Defining a BoundaryWe contend with boundaries every day. Although boundaries can take many forms—physical, financial, mental—in the end theyre nothing more than an indication of a limit.To make a boundary work, you define its limits and take appropriate action when (or justbefore) those limits are exceeded. Think of driving a car: lines on the road define theboundaries within which the car is supposed to remain. If youre approaching the line onthe left (the left boundary), you move the steering wheel to adjust; if youre approachingthe line on the right, you adjust in the opposite direction—conditional logic in action!Written in ActionScript, those actions might look like this:if (car_mc._x < leftOfRoad) { turnWheel (right);} else if (car_mc._x > rightOfRoad) { turnWheel (left);}To make a boundary work in Flash, you must define its limits and use an if statement tocheck the affected element each time an event occurs that might cause the element toexceed its defined boundaries. This concept will become clearer as we progress throughthe following exercise.For example, boundaries in Flash might be used to do the following: • Prevent the properties of movie clip instances (including x, y, alpha, xscale, yscale, and so on) from being changed beyond specified amounts • Invoke an action (property change or method) when an element is within or exceeds a specified boundary • Prevent data values from exceeding defined limits (useful when validating data)In the following exercise, well dynamically animate the red bars at the top of the projectto represent a moving launch window through which the rocket must pass to complete asuccessful launch. 1. Open rocketLaunch2.fla. Well continue building on the file you worked with in the preceding exercise.2. With the Actions panel open, select Frame 1 of the Actions layer and add this script at the end of the current script:3.4. var direction:String;5.6. function launchWinMove(){7.8. if (launchWindow_mc._x < 0) {9.10. direction = right;11.12. } else if (launchWindow_mc._x > 550) {13.14. direction = left;15.16. }17.18. if (direction == right) {19.20. launchWindow_mc._x = launchWindow_mc._x + 3;21.22. } else {23.24. launchWindow_mc._x = launchWindow_mc._x - 3;25.26. }27.28. }29.30. _root.onEnterFrame = launchWinMove;31. Three changes occur with this added script: you create the direction variable, define the launchWinMove() function (which uses the direction variable), and set the launchWinMove() function to be triggered with an onEnterFrame event. Lets look at how the function works. The two red bars at the top of the stage are part of the composite movie clip instance named launchWindow_mc. The function in this step uses two ifstatements to move this movie clip instance back and forth from left to right.Triggering this function using the onEnterFrame event causes these statements tobe evaluated 24 times per second (the frame rate of the movie).The first statement analyzes the position of the launchWindow_mc instance as itmoves within a specified boundary. The statement says that if the horizontal (x)position of this instance is less than 0—that is, its center point exceeds the leftboundary of the stage—set the value of direction to right. If the horizontalposition is greater than 550—its center point exceeds the right boundary of thestage—set the value of direction to left. The value of direction changes only ifone of the limits of the boundary is exceeded. This will occur as a result of themovie clip instance being put into motion in the next if statement. This statementsays that if direction has a value of right, move the instance to its currenthorizontal position plus 3. This action moves the instance to the right. Otherwise(else), if direction has a value of left, move the instance to its current horizontalposition minus 3. This action moves the instance to the left. When these two ifstatements are analyzed and their actions executed 24 times a second, the red barsare set into motion, but the movement of the bars is restricted to a specified area.NOTEWhen creating boundaries in your scripts, note which event handler might causean element to exceed a boundary, and use that event to analyze the boundaryconditional statement. For example, if you want to take a specific action whenevera movie clip instances vertical position exceeds an established boundary whilebeing dragged around the stage, the mouseMove event handler would be an idealchoice because it can easily cause a dragged movie clip instance to exceed itsboundary.These two if statements in our script work in harmony. The direction of themovement in launchWindow_mc is determined by the boundary it last exceeded(which sets the value of direction to either left or right)—that is, movement isin the opposite direction of the boundary exceeded. Eventually a boundary will beexceeded again, and the process will be repeated in the opposite direction. In otherwords, if direction has a value of right, the instance will move right, eventuallyexceeding the right part of the boundary—at which point the value of direction isset to left and the process is reversed. The instances initial position on the stage is one pixel past the left boundary. When this script is first executed, direction is set to right and the instance moves to the right.3. Choose Control > Test Movie to test the projects functionality so far. When the movie plays, the red bars are set into motion. When either boundary defined in Step 2 is exceeded, the bar moves in the opposite direction.4. Close the test environment to return to the authoring environment, and save your work as rocketLaunch3.fla. Well build on this ...
Nội dung trích xuất từ tài liệu:
Defining a Boundary < Day Day Up >Defining a BoundaryWe contend with boundaries every day. Although boundaries can take many forms—physical, financial, mental—in the end theyre nothing more than an indication of a limit.To make a boundary work, you define its limits and take appropriate action when (or justbefore) those limits are exceeded. Think of driving a car: lines on the road define theboundaries within which the car is supposed to remain. If youre approaching the line onthe left (the left boundary), you move the steering wheel to adjust; if youre approachingthe line on the right, you adjust in the opposite direction—conditional logic in action!Written in ActionScript, those actions might look like this:if (car_mc._x < leftOfRoad) { turnWheel (right);} else if (car_mc._x > rightOfRoad) { turnWheel (left);}To make a boundary work in Flash, you must define its limits and use an if statement tocheck the affected element each time an event occurs that might cause the element toexceed its defined boundaries. This concept will become clearer as we progress throughthe following exercise.For example, boundaries in Flash might be used to do the following: • Prevent the properties of movie clip instances (including x, y, alpha, xscale, yscale, and so on) from being changed beyond specified amounts • Invoke an action (property change or method) when an element is within or exceeds a specified boundary • Prevent data values from exceeding defined limits (useful when validating data)In the following exercise, well dynamically animate the red bars at the top of the projectto represent a moving launch window through which the rocket must pass to complete asuccessful launch. 1. Open rocketLaunch2.fla. Well continue building on the file you worked with in the preceding exercise.2. With the Actions panel open, select Frame 1 of the Actions layer and add this script at the end of the current script:3.4. var direction:String;5.6. function launchWinMove(){7.8. if (launchWindow_mc._x < 0) {9.10. direction = right;11.12. } else if (launchWindow_mc._x > 550) {13.14. direction = left;15.16. }17.18. if (direction == right) {19.20. launchWindow_mc._x = launchWindow_mc._x + 3;21.22. } else {23.24. launchWindow_mc._x = launchWindow_mc._x - 3;25.26. }27.28. }29.30. _root.onEnterFrame = launchWinMove;31. Three changes occur with this added script: you create the direction variable, define the launchWinMove() function (which uses the direction variable), and set the launchWinMove() function to be triggered with an onEnterFrame event. Lets look at how the function works. The two red bars at the top of the stage are part of the composite movie clip instance named launchWindow_mc. The function in this step uses two ifstatements to move this movie clip instance back and forth from left to right.Triggering this function using the onEnterFrame event causes these statements tobe evaluated 24 times per second (the frame rate of the movie).The first statement analyzes the position of the launchWindow_mc instance as itmoves within a specified boundary. The statement says that if the horizontal (x)position of this instance is less than 0—that is, its center point exceeds the leftboundary of the stage—set the value of direction to right. If the horizontalposition is greater than 550—its center point exceeds the right boundary of thestage—set the value of direction to left. The value of direction changes only ifone of the limits of the boundary is exceeded. This will occur as a result of themovie clip instance being put into motion in the next if statement. This statementsays that if direction has a value of right, move the instance to its currenthorizontal position plus 3. This action moves the instance to the right. Otherwise(else), if direction has a value of left, move the instance to its current horizontalposition minus 3. This action moves the instance to the left. When these two ifstatements are analyzed and their actions executed 24 times a second, the red barsare set into motion, but the movement of the bars is restricted to a specified area.NOTEWhen creating boundaries in your scripts, note which event handler might causean element to exceed a boundary, and use that event to analyze the boundaryconditional statement. For example, if you want to take a specific action whenevera movie clip instances vertical position exceeds an established boundary whilebeing dragged around the stage, the mouseMove event handler would be an idealchoice because it can easily cause a dragged movie clip instance to exceed itsboundary.These two if statements in our script work in harmony. The direction of themovement in launchWindow_mc is determined by the boundary it last exceeded(which sets the value of direction to either left or right)—that is, movement isin the opposite direction of the boundary exceeded. Eventually a boundary will beexceeded again, and the process will be repeated in the opposite direction. In otherwords, if direction has a value of right, the instance will move right, eventuallyexceeding the right part of the boundary—at which point the value of direction isset to left and the process is reversed. The instances initial position on the stage is one pixel past the left boundary. When this script is first executed, direction is set to right and the instance moves to the right.3. Choose Control > Test Movie to test the projects functionality so far. When the movie plays, the red bars are set into motion. When either boundary defined in Step 2 is exceeded, the bar moves in the opposite direction.4. Close the test environment to return to the authoring environment, and save your work as rocketLaunch3.fla. Well build on this ...
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 XMLTài liệu có liên quan:
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 297 0 0 -
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 297 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 281 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 278 1 0 -
47 trang 250 4 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 246 0 0 -
80 trang 238 0 0
-
6 trang 229 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 226 0 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 223 0 0