Button generation
Package com. UI
{
Import Flash. display. simplebutton;
Import Org. osmf. layout. absolutelayoutfacet;
Public Class Button Extends Simplebutton
{
Public Function Button (thistext: String ): Void
{
VaR Arr: array = Init (thistext );
Super (ARR [0], arr [1], arr [2], arr [2]); // Call the constructor function of the parent class
}
Private Function Init (thistext: String ): Array
{
VaR Atext: text = new text (thistext );
VaR Btext: text = new text (thistext );
VaR Ctext: text = new text (thistext );
VaR A: mysprite = new mysprite (0xffff00 );
VaR B: mysprite = new mysprite (0x00ff00 );
VaR C: mysprite = new mysprite (0x0000ff );
A. addchild (atext );
B. addchild (btext );
C. addchild (ctext );
VaR ABC: array = [a, B, c];
Return ABC;
}
}
}
Plotting
Package com. UI
{
Import Flash. display. Sprite;
Public Class Mysprite Extends Sprite
{
Public Function Mysprite (COL: uint): void
{
Init (COL );
}
Private Function Init (COL: uint): void
{
This. Graphics. beginfill (COL );
This. Graphics. drawrect );
This. Graphics. endfill ();
}
}
}
Document Type
Package
{
Import Com. UI. Button;
Import Flash. display. Sprite;
Import Flash. Events. event;
Import Flash. Events. mouseevent;
Public Class Main Extends Sprite
{
Private VaR Isdown: Boolean = False ;
Private VaR Oldx: Number ;
Private VaR Oldy: Number ;
Private VaR Ceng: SPRITE; // Drawing Layer
// ---------------------------------------------
Private VaR Dataarr: array = new array (); // Array that records the mouse position
Private VaR CI: uint = 0; // Record the number of times added to the array during plotting
Private VaR Huici: uint; // Record the playback step to the array during playback
Private VaR A: button; // Redraw button
Private VaR B: button; // Clear button
Public Function Main (): void
{
Init ();
}
Private Function Init (): void
{
// Create two buttons and listen for button-clicking events
A = new button ("redraw ");
A. X = 400;
A. Y = 300;
B = new button ("clear ");
B. x = 400;
B. Y = 340;
This. addchild ();
This. addchild (B );
A. addeventlistener (mouseevent. Click, draw );
B. addeventlistener (mouseevent. Click, clear );
// Create a Drawing Layer
Ceng = new sprite ();
This. addchild (Ceng );
// Listen to the three actions of the mouse (press, move, and lift)
This. Stage. addeventlistener (mouseevent. mouse_down, ondown );
This. Stage. addeventlistener (mouseevent. mouse_move, onmove );
This. Stage. addeventlistener (mouseevent. mouse_up, onup );
}
Private Function Ondown (EVT: mouseevent): void
{
Oldx = This. Stage. mousex;
Oldy = This. Stage. Mousey;
If (A. hittestpoint (this. Stage. mousex, this. Stage. Mousey, True ) | B. hittestpoint (this. Stage. mousex, this. Stage. Mousey, True ))
{
Isdown = False ;
}
Else
{
Isdown = True ;
Dataarr [CI] = new array (oldx, Oldy ); // Record the coordinates of the first step in the playback Array
}
}
Private Function Onmove (EVT: mouseevent): void
{
If (Isdown = True )
{
CI ++; // Increase in times
Ceng. Graphics. linestyle (2, 0xff0000 );
Ceng. Graphics. moveTo (oldx, Oldy );
Ceng. Graphics. lineto (stage. mousex, stage. Mousey );
Oldx = stage. mousex;
Oldy = stage. Mousey;
Dataarr [CI] = new array (oldx, Oldy ); // Records the coordinates of each step in the playback array.
}
}
Private Function Onup (EVT: mouseevent): void
{
Isdown = False ;
}
// Redraw
Private Function Draw (EVT: mouseevent): void
{
This. Stage. addeventlistener (event. enter_frame, huizhi );
}
// Execute playback
Private Function Huizhi (EVT: Event): void
{
// If the number of times drawn is smaller than the length of the array, you can continue playback.
// When drawing, the starting value is 0. If the draw length is 100, the number of draws must be less than the total length.
If (Huici <(dataarr. Length-1 ))
{
Ceng. Graphics. linestyle (000000 X );
Ceng. Graphics. moveTo (dataarr [Huici] [0], dataarr [Huici] [1]);
Huici ++;
Ceng. Graphics. lineto (dataarr [Huici] [0], dataarr [Huici] [1]);
}
Else
{
// Clears the number of draws
Huici = 0;
// Remove listener
This. Stage. removeeventlistener (event. enter_frame, huizhi );
}
}
// Clear
Private Function Clear (EVT: mouseevent): void
{
Ceng. Graphics. Clear ();
}
}
}