« Home « Kết quả tìm kiếm

Creating an Interactive Placeholder


Tóm tắt Xem thử

- The great thing about loading external content into an instance that has been scripted in such a way is that even though the instance's content will change, its scripted functionality can remain the same.
- placeholder_mc._rotation.
- If you attach this script to the main timeline, the placeholder_mc instance rotates 30 degrees each time the mouse is clicked.
- This instance can be thought of as an interactive placeholder because any external movie or JPG loaded into it will also rotate when the mouse is clicked.
- The only thing that changes is the instance's content..
- When we worked with this file in the preceding exercise, we set the movie to dynamically load JPGs into the movie clip instance named placeholder_mc.
- In this exercise, we'll add ActionScript to make the loaded content draggable and to scale it 150 percent when the mouse button is pressed.
- The ActionScript will also ensure that when the mouse button is released, dragging ceases and the content is scaled back to 100 percent.
- var placeholderStartX:Number = placeholder_mc._x;.
- var placeholderStartY:Number = placeholder_mc._y;.
- This script creates two variables whose values represent the initial x and y positions of the placeholder_mc movie clip instance, into which our JPGs are loaded.
- It allows the values to change automatically if the instance is moved to a new point on the stage during development..
- if (placeholder_mc.hitTest(_xmouse, _ymouse)){.
- maskClip_mc._x = placeholderStartX;.
- maskClip_mc._y = placeholderStartY;.
- placeholder_mc.setMask(maskClip_mc);.
- placeholder_mc._xscale = 150;.
- placeholder_mc._yscale = 150;.
- This step attaches an onMouseDown event handler to the main timeline, causing the script to execute whenever the mouse button is pressed.
- An if statement determines whether the mouse pointer is over the placeholder_mc instance when the mouse is pressed.
- In other words, because our JPG images are being loaded into this instance, these actions execute only if the mouse button is pressed while the pointer is on top of the image..
- The first two actions within the if statement dynamically position the black rectangle maskClip_mc movie clip instance so that its x and y values equal placeholderStartX and placeholderStartY, respectively.
- This action places the maskClip_mc instance directly over the placeholder_mc instance during this script's execution..
- The next action dynamically sets the maskClip_mc instance to mask the.
- placeholder_mc instance's content—necessary because the next two lines in the script scale the size of placeholder_mc by 150 percent.
- placeholder_mc contents, those contents appear to remain within the panel window even though placeholder_mc becomes larger..
- The last action in the event handler makes the placeholder_mc movie clip instance draggable..
- This script—executed when the mouse button is released—simply reverses the actions that occur when the mouse button is pressed.
- then the next several lines use a with statement to perform a set of actions in relation to the placeholder_mc instance.
- The first action removes the mask from the instance..
- The next two actions scale the instance back to its original size.
- When the mouse button is pressed, the image becomes larger and draggable, and the dynamic mask we set up takes effect.
- Release the mouse button, and you'll see maskClip_mc.
- The reason for this is that when our script removed the masking effect, we didn't compensate for the fact that maskClip_mc would become visible again as a normal clip.
- maskClip_mc._visible = false;.
- This line of script makes the instance invisible as soon as it loads, and it remains this way because our movie doesn't contain an action to change it.
- Because the instance is invisible, it won't interfere with viewing the images in the.
- placeholder_mc instance, even when the masking effect is disabled..
- With the mouse button pressed, the image becomes larger and draggable, and the dynamic mask we set up takes effect.
- Release the mouse button, and the image.
- This time, maskClip_mc no longer appears, because it's invisible..
- The image's.
- functionality resides not within the loaded asset, but in the instance into which the asset is loaded (placeholder_mc).
- although the loaded content may change, the instance and its functionality remain the same.

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt