|
ClipControl
The ClipControl widget controls any movieClip object in Flash, changing the properties of the clip (e.g. width, x or y position, alpha, frame number, etc.) based on input values from another widget. For example, the output value from an ../AnalogInput widget monitoring a proximity sensor can control the left/right (x property) position of a graphic across the screen to reflect the position of a person in relation to a wall. In addition, more than one property of a clip (scale and alpha for example) can be controlled by having multiple ClipControl widgets control the same clip.
Since the values used by ClipControl are directly translated into the property of the clip, be sure the widget or code sending values to ClipControl are in the appropriate range. For example, if you are using ../AnalogInput as the inputSource, and you are controlling the horizontal position of a graphic, you should set the MIN of ../AnalogInput to 0 and the MAX to the width of the Flash movie. In this case, an incoming value of 0 would put the graphic at the left side of the screen, and if the screen is 640 pixels wide, then an incoming value of 640 would position the graphic at the right side of the screen (note that the registration point of the clip the exact positioning). See the individual properties listed below for their appropriate ranges.
On-screen Features
IN:Shows the values coming from the inputSource as well as the instance name of the inputSource
- OUT: Shows the property of the clip being controlled, and the instance name of the clip
Parameters
- CLIP: the instance name of the movieClip you want to control
- INVISIBLE: if set to "yes", the widget will disappear when the Flash movie is run
INPUT SOURCE the instance name of the source the widget listens to, e.g ../AnalogInput or ../DigitalInput
THE PROPERTY: the property of the movieClip that will be affected. properties supported are width, height, scale, x & y position, rotation, alpha (opacity), movieClip frame number, and iosFeed.
width/height: 0 to the maximum pixels of widthheigth desired
scale: 0 to the maximum percentage scale. Eg. 200% will make the clip twice its normal size. negative numbers will work, reversing and inverting the clip.
x/y: 0 to the maximum horizontal or vertical position desired. Note that for x, zero is on the left of the screen, and for y, zero is at the top of the screen. Negative numbers will place the clip off the screen to the left or above.
rotation: 0 to 180 indicating the number of degrees rotation. Multiples of 180 rotate the clip a full revolution. Similarly, negative numbers rotate counterclockwise in multiples of 180.
alpha: 0 to 100, where 0 is completely transparent, and 100 is completely opaque
frame no: 1 to the highest frame in the clip. This setting will position the clip to a specific frame number of the clip's timeline
netFeed: Any number. Instead of controlling a specific property of the clip, a setting of netFeed invokes an ActionScript function on the target clip so the clip code can do specific things with the values feed to it. The function called is netFeed(feedValue, feedID) where value is the value being sent by ClipControl, and feedID is the instance name of the ClipControl component on the stage -- the feedName helps in the case where a clip is receiving netFeeds from multiple sources and allows the code to distinguish between the sources. Note: in versions prior to 1.0, the function called was iosFeed -- this is now fixed and the correct netFeed function is called.
netFeed Explanation & Code Examples
If you use the netFeed capability, the clipControl will send the actual sensor value to the indicated movieClip. For this to work, a function needs to be associated with that movieClip. An example of this is where you want the movieClip to rotate to the left for sensor values less than 50, and rotate to the right for values 50 or greater. Placing the following code on the movieClip named in the parameters would accomplish this:
onClipEvent (load) {
function netFeed(feedValue) {
if (feedValue<50) {
this._rotation -= 10;
} else if (feedValue>=50) {
this._rotation += 10;
}
}
}
In a more complex example, it is possible to target the _root timeline as the movieClip in the "clip" parameter, and thus cause a function defined in the first frame to be executed. This example changes the color of a movieClip on the stage called "clip1". It assume there are three ClipControl widgets on stage, with instance names of "red" "green" and "blue".
import flash.geom.ColorTransform;
redMultiplier = 0;
greenMultiplier = 0;
blueMultiplier = 0;
function netFeed(feedValue, feedID) {
if (feedID == "red") {
redMultiplier = feedValue/100;
} else if (feedID == "green") {
greenMultiplier = feedValue/100;
} else if (feedID == "blue") {
blueMultiplier = feedValue/100;
}
_root.clip1.transform.colorTransform = new ColorTransform(redMultiplier,greenMultiplier,blueMultiplier,1,0,0,0,0);
}