Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 6 of 6

Thread: New HitTest method of Actionscript 3.0

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,452
    Rep Power
    8

    New HitTest method of Actionscript 3.0

    amazing Flash templates
    The good old hitTest " method has been removed, or better, it"s been split into 2 separate methods called hitTestObject and hitTestPoint.
    The use of these methods isn"t much different from the old hitTest.
    Let"s see how they work"
    The Document Class I"ve created is this:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.events.Event;
    	import flash.events.MouseEvent;
    	import flash.text.TextField;
    	
    	public class ProvaNuovoHitTest extends MovieClip
    	{
    		public function ProvaNuovoHitTest()
    		{
    			primoCaso();
    			secondoCaso();
    		}
    		
    		private function primoCaso():void
    		{
    			black_mc.addEventListener(Event.ENTER_FRAME,controllaMouse);
    		}
    		
    		private function controllaMouse(e:Event):void
    		{
    			if(black_mc.hitTestPoint(mouseX,mouseY,true))
    				debug_0_txt.text='si';
    			else
    				debug_0_txt.text='no';
    		}
    		
    		private function secondoCaso():void
    		{
    			circle_1_mc.buttonMode=true;
    			circle_1_mc.addEventListener(MouseEvent.MOUSE_DOWN,sposta);
    			circle_1_mc.addEventListener(MouseEvent.MOUSE_UP,ferma);
    		}
    		
    		private function sposta(m:MouseEvent):void
    		{
    			circle_1_mc.startDrag(true);
    			circle_1_mc.addEventListener(Event.ENTER_FRAME,controllaContatto);
    		}
    		
    		private function controllaContatto(e:Event):void
    		{
    			if(circle_1_mc.hitTestObject(circle_0_mc))
    				debug_1_txt.text='si';
    			else
    				debug_1_txt.text='no';
    		}
    		
    		private function ferma(m:MouseEvent):void
    		{
    			circle_1_mc.stopDrag();
    			circle_1_mc.removeEventListener(Event.ENTER_FRAME,controllaContatto);
    		}
    	}
    }
    Here is the result:







    Let"s analyze the code:

    In the primoCaso ( method ) the script checks if the clip hits the mouse with the event ENTER_FRAME.
    In this case I use the method hitTestPoint with its 3 parameters:
    -x of the point
    -y of the point
    -forma: it"s a Boolean value ( true/false ) with which you can decide if you want to apply hitTestPoint only to the real shape of the object or to the containing frame.
    I suggest you try to change that value to better understand the difference J

    In the secondoCaso ( method ) I control if the red MovieClip ( moveable ) hits the blue one using the hitTestObject method with its only parameter ( the actual object with which we"re checking the collision ).
    With the hitTestObject method, you can"t choose to apply it to the containing frame. In order to do so, advanced trigonometry algorithms and complicated Actionscript is required ( we"ll see it later ).

    Later !

  2. #2
    Junior Member Settled In esviridc is on a distinguished road
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Re: New HitTest method of Actionscript 3.0

    hey!
    i'm a new member, sorta a beginner at all of this. I was able to get the other dragging tutorials to work, but I am not sure as to how to actually transfer this code into my actions. the "private function" and the italian is throwing me off... please help.

    by the way: this is an amazing website! much more helpful than anything i have come across as of yet. thank you for doing this for people!

  3. #3
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,452
    Rep Power
    8

    Re: New HitTest method of Actionscript 3.0

    Hi and welcome

    Do you mean transfer the code into timeline ?

  4. #4
    Junior Member Settled In anujsharma181 is on a distinguished road
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Re: New HitTest method of Actionscript 3.0

    Hi
    I am trying to drag and drop multiple instances of UILoader on stage. My goal is if user puts UILoader partially on top of other UILoader , it should just stay on top of it. If user puts on top of UILoader more than the central point of other UILoader, the other UILoader will change the color of its border and on mouse release gets replaced by the placed UILoader.
    I am successful in getting all this but I am getting inconsistent results as an output. Sometimes I have to put exactly on top of other UILoader to replace it and sometimes I just touch the UILoader and it shows red border and gets replaced. I used the logic of calculating the center of rectangle(my UILoader container) and use hitPoint method, and as soon as dragged UILoader hits the calculated center of UILoader, it gets replaced.
    Please help me out in where I am messing things up.Any better idea than this will also be highly appreciated.
    ( Following is the function which is telling my UILoader to replace of stopDrag.)
    Thanks a lot
    Anuj
    /
    Code:
    *************************CODE***************/
    function dropUILoader(e:MouseEvent):void
            {
               
                if(e.target    is UILoader)
                {
                    var myUILoader:UILoader = e.target as UILoader;
    
                if (mouseY<746)
                {
                    myUILoader.stopDrag();
                    //Putting video on top of already existed videos
                    var trackChild:Number=container.getChildIndex(myUILoad  er);
                    var childContainer:DisplayObject= container.getChildAt(trackChild);
                    for (var z:Number=0; z<=container.numChildren-1; z++)
                    {
                        var restChild:DisplayObject=container.getChildAt(z);
                       
                        if (childContainer!=restChild)
                        {
                            if(restChild is UILoader)
                            {
                                var cRC:UILoader=restChild as UILoader;                               
                                var regcRCx:Number=cRC.x;
                                var regcRCy:Number=cRC.y;
                               
                                var regcRCWidth:Number=cRC.width;
                                var regcRCHeight:Number=cRC.height;
                                                   
    if(childContainer.hitTestPoint(((regcRCx+regcRCWid th)/2),(regcRCy+regcRCHeight)/2)==true) 
                                {
                                    trace("Totally Hit");   
                                    container.removeChild(cRC);
                                }   
                                else
                                {
                                    trace("Partially Hit");   
                                }
                            }
                        }
                    }
                }               
                else
                {
                    myUILoader.unload();
                    container.removeChild(myUILoader);
                }
                }
            }
    Last edited by Flep; 13-03-08 at 04:29. Reason: added code tags

  5. #5
    Junior Member Settled In flashkid101 is on a distinguished road
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Question Re: New HitTest method of Actionscript 3.0

    I am totally new to actionscript. So I am sure this sounds totally basic but was wondering if you can help:

    I want to set up a project combining two of your scripts:

    Part 1) Magnifying Glass: Have a magnifying glass that you can drag around the stage.

    Part 2) Say we are looking at a map thru the magnifying glass. When the lense is positioned over a specific country, the lense handle will change color OR becomes invisible (just as long as we can set its properties as a movie clip).

    Not sure if I am explaining this clearly but I hope it makes sense.

    Thanks for your help.

  6. #6
    Junior Member Settled In flashkid101 is on a distinguished road
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Re: New HitTest method of Actionscript 3.0

    Can anyone help with this please?

    Thanks!

+ Reply to Thread

Similar Threads

  1. curveTo Method with Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 1
    Last Post: 23-01-10, 17:18
  2. domanda su hittest
    By obhund in forum Flash Italiano
    Replies: 0
    Last Post: 12-02-09, 18:34
  3. Actionscript 3.0 perlinNoise method
    By Flep in forum Tutorials
    Replies: 6
    Last Post: 05-12-08, 10:05
  4. Replies: 0
    Last Post: 14-10-08, 06:26
  5. Replies: 0
    Last Post: 09-10-07, 19:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO