Creating runtime data bindings using ActionScript 579
4. In the Actions panel, enter the following code:
this.createEmptyMovieClip("canvas_mc", 999);
var isDrawing:Boolean = false;
//
clear_btn.onRelease = function() {
canvas_mc.clear();
};
//
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
canvas_mc.lineStyle(5, 0xFF0000, 100);
canvas_mc.moveTo(_xmouse, _ymouse);
isDrawing = true;
};
mouseListener.onMouseMove = function() {
if (isDrawing) {
canvas_mc.lineTo(_xmouse, _ymouse);
updateAfterEvent();
}
};
mouseListener.onMouseUp = function() {
isDrawing = false;
};
Mouse.addListener(mouseListener);
5.
Select Control > Test Movie to test the document.
6. Drag your pointer to draw a line on the Stage.
7. Click the button to erase what you’ve drawn.
Creating runtime data bindings using
ActionScript
If you use components to create applications, it’s often necessary to add bindings between
those components so that you can interact with data or have components interact with each
other. Interaction between components is necessary for creating usable forms or interfaces that
your users can interact with. You can use the Bindings tab in the Component inspector to add
bindings between components on the Stage. You can use the Bindings tab in the Component
inspector to bind data between components on the Stage.
For more information on using the Bindings tab, see “Working with bindings in the Bindings
tab (Flash Professional only)” on page 403 in Using Flash. You can also find additional
information in the following online articles: Building a Tip of the day Application (Part 2),
Data Binding in Macromedia Flash MX Professional 2004, and Building a Google Search
Application with Macromedia Flash MX Professional.