How to use Flash hitTest() for adding interactivity |
| Written by AnaS | |
|
1. Create a new Flash document about 400x200. Insert three new layers. Name the layers actions, circle, square, text starting from the top.
2. In the first frame of the circle layer draw a green circle about 50x50. Double-click it to select both stroke and fill and choose Modify>>Convert to Symbol (F8). Set circleMC for the name, MovieClip as type and center to registration point as in the picture below: 3. In the first frame of the square layer draw an orange square about 60x60. Double-click it to select both stroke and fill and choose Modify>>Convert to Symbol (F8). Set squareMC for
the name, MovieClip as type and center to registration point as in the picture below: 4. Now click the circle to select it and in the Properties panel type the instance name circle_mc, set X: 20 and Y: 75. Click also the square and give it an instance name of square_mc. Set for square_mc X: 300 and Y: 70. 5. Now go to the first frame of the text layer and make a click to select it. Select the Text Tool (T) from the tool panel. In the Properties panel choose Dynamic Text for Text Type drop-down list, Arial font, size 14, color black (#000000). Give it also an instance name of hit_txt. 6. Great job! Now go in the first frame of the actions layer press F9 to open the Actions panel and put in the following ActionScript code:
hit_txt.text="Not hit!";
circle_mc.onRelease = circle_mc.onReleaseOutside = function(){ 7. Test the movie (Ctrl+Enter). You will see that in the hit_txt is displayed Hit! if the circle_mc overlaps square_mc, and Not hit! if not. You need to Register in order to download the FLA file. Hope it helps!
written by Kush , August 14, 2007
Can we remove hand impression on rollover effect I want a normal cursor Please Explain
written by AMS , September 02, 2007
How can we have multiple circles and multiple squares. Trying to use this as a drag and drop rating system. So, the circle could be dropped into any square to be 'rated'.
written by I. hari Kiran , September 05, 2007
action scripting used in creating web designing and creating own and new animations. Tutorials and projects for Flash. and DreamWeaver tutorials, creating web pages and scripting such as using HTML and CSS for creating web pages and their application
written by Bob Dole , October 04, 2007
I need to know how to make a hit test for a key-controlled object. Help?
written by daniel tilley , October 15, 2007
""I need to know how to make a hit test for a key-controlled object. Help? "" yes you can mate, use someting like this onClipEvent (load){ speed = 5 } onClipEvent (enterFrame){ if (Key.isDown(Key.UP)){ this._y -= speed } if (this.hitTest(BALL_MC)){ gotoAndStop (1) } } NOTE:! BAQLL_MC is the object that you are hitting, can be changed, hope this helps.
written by daniel tilley , October 15, 2007
""Can we remove hand impression on rollover effect I want a normal cursor Please Explain "" TBH i dont know much java but what i would do, is save the cursur you would like to use in the directory of the movie. then import it into flash and use this script on it. onClipEvent (enterFrmae){ Mouse.hide; this._x = Mouse._x this._y = Mouse._y } then obviously yo will need to set boundries, but basicaly the consept is to hide the mouse and use the image as the cursur, then this allows you to use all diferent cursurs and effects etc. P.S am a little bit drunk so that code may make no sence but it is the way to do it.
written by Ephenia Moshweu , December 05, 2007
please help. mize game the problem is that my character are moving through the walls. Can you hepl me.
written by Emily , December 05, 2007
how to make an action for the maze character that is not controlled by the keyboard
written by Jake , December 05, 2007
Hey i have a question....I can not figure out how to make Multiple hit tests...Say i have 3 enemys that look totally different. How can i make a "lazer" hit each seperate one?
written by Dylan Bosman , February 16, 2008
I need help with my Space Shooter - side scrolling (very first game). the ship moves fine and shoots fine. The problem comes in when i have to perform a hitTest on the enemy and the bullet. this is my code so far.... //ship or hero MC moving and shooting 100% fine onClipEvent(load){ this.speed=10; this.shotcount=0.3; this.isshot=0; } onClipEvent (enterFrame) { //to move the ship if (Key.isDown(Key.LEFT)) { _root.ship._x=(this._x-10); } if (Key.isDown(Key.RIGHT)) { _root.ship._x=(this._x 10); } if (Key.isDown(Key.UP)) { _root.ship._y=(this._y-10); } else if (Key.isDown(Key.DOWN)) { _root.ship._y=(this._y 10); } //to set boundaries so ship doesn't go off sreen if (_root.ship._x=650) { _root.ship._x=650; } if (_root.ship._y=380) { _root.ship._y=380; } //to shoot actual bullet if(Key.isDown(Key.SHIFT)&&this.isshot==0){ this.isshot=1; _root.shot.duplicateMovieClip( "shot" this.shotcount, this.shotcount 4000 ); this.shotcount ; }else{ this.isshot=0; } } //code on bullet MC 100% fine onClipEvent(load){ if(this._name=="shot"){ this._visible=false; }else{ this._visible=true; } this.speed=50; this._x=_root.ship._x 40; this._y=_root.ship._y 7; } onClipEvent(enterFrame){ this._x =this.speed; this._y =this.yspeed; if(this._x>700){ this.removeMovieClip(); } } } My bad guy has an instance name of "enemy". How can i perform a hit test on it so it disappears on contact with bullet (instance name = shot)???? Any help would be greatly appreciated since this is my first game and i want it to work since i am a big fan of flash games. Thanks..:) Do you need more help? Ask now!
|
|
| Last Updated ( Friday, 28 March 2008 ) |