i've edited following code in order let green rectangles follow cursor customized small rectangle. i've encountered several problems:
- although haven't defined coordinate in separate class, size abviously wrong in stage when publish half size cursor coordinate.
- the reset button cannot activated, although i've tested in other code. here work i've published: http://neowudesign.com/hwu_ex04.html
the code on timeline
//hw//creating new cursor newcursor.startdrag ("true"); mouse.hide(); //hw//creating holder hold butterfly objects var mothholder = new sprite(); addchild(mothholder); //hw//creating 7 moths @ beginning makemoths(7); //hw//creating function can generate limited numbers of moths. function makemoths(mothsnumber:number) { (var = 0; < mothsnumber; i++) { newmoth = new moth(); mothholder.addchild(newmoth); } } //hw//set reset button @ top clicking, it's failed work; //hw//set cursor default one, , remove custom 1 when hovering; mothholder.setchildindex(reset,mothholder.numchildren); reset.addeventlistener(mouseevent.mouse_over, cursorchange); function cursorchange(event:mouseevent):void { mouse.show(); newcursor.visible = false; trace("alert!!"); } //hw//creating function of reset reset.addeventlistener(mouseevent.click, resetclick, false, 0, true); function resetclick(evt:mouseevent):void { removechild(mothholder); mothholder = new movieclip(); addchild(mothholder); var nummoths:number = math.round(math.random() * 6) + 1; trace("moths numeber: "+ nummoths); makebutterflies(numbutterflies); } //hw//when cursor leave reset region, turns customized 1 reset.addeventlistener(mouseevent.mouse_out, fl_mouseouthandler); function fl_mouseouthandler(event:mouseevent):void { removeeventlistener(mouseevent.mouse_over, cursorchange); mouse.hide(); newcursor.visible = true; }
and code class "moth" separately named "angle.as"
package { import flash.display.movieclip; import flash.events.event; import flash.geom.point; public class angle extends movieclip { var speed:number = 8; function angle() { //letting every moth follow moving of cursor addeventlistener(event.enter_frame,mothmove); function mothmove(myevent:event) { trace(mousex); trace(mousey); var angle:number = math.atan2(mousey - y, mousex - x); x += math.cos( angle ) * speed; y += math.sin( angle ) * speed; } } } }
Comments
Post a Comment