René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Hit test [Ming wrapper example] | ||
This example demonstrates the Action Script function
hitTest .
When the mouse is pressed, it is checked whether it is pressed on a shape or not. If so, the shape can then be dragged.
See also Dragging.html and Dragging II.
This flash movie was created with the following program. HitTest.cpp
#include "SWFMovie.h" void AddDragable(Movie& movie, Shape shape, int x, int y) { static Action mouseDown( "if (!_root.isDragging && " " hitTest(_root._xmouse,_root._ymouse, true)) " " { _root.isDragging = true; startDrag();};" ); static Action mouseUp( "if ( _root.isDragging) " " { _root.isDragging =false; stopDrag ();};" ); MovieClip clip; clip.Add(shape); DisplayClip iClip = movie.Add(clip); iClip.MoveTo( x, y); iClip.OnMouseDown(mouseDown); iClip.OnMouseUp (mouseUp ); clip.NextFrame(); } int main() { Movie movie ("HitTest.swf", 400, 400 /*, 15, 7*/); movie.BackgroundColor(0x33, 0x44, 0x55); Shape shape; shape.FillStyle(0xff, 0x7f, 0x00); shape.Line( 100, 0); shape.Line( 0, 100); shape.Line(-100, 0); shape.Line( 0,-100); AddDragable(movie, shape, 50, 70); AddDragable(movie, shape, 90, 220); Shape redLine; redLine.LineStyle( 3, 0xff, 0x00, 0x00); redLine.LineTo (12, 14); redLine.LineTo (42, 75); redLine.LineTo (18,-12); AddDragable (movie, redLine, 150, 180); Shape greenLine; greenLine.LineStyle( 3, 0x00, 0xff, 0x7f); greenLine.LineTo ( 12, 14); greenLine.LineTo ( 72, 35); greenLine.LineTo (-18, 42); AddDragable (movie, greenLine, 250, 180); movie.NextFrame(); return 0; } This is one of a series of examples that demonstrates the C++ ming wrapper classes. Other examples can be found here.
|