A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Moving a Class into a Movie Clip? Error #2007

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    21

    Moving a Class into a Movie Clip? Error #2007

    I've just started learning about classes and Flash in general.

    I created a little Flash file that used classes and all was working well.

    But then I decided I wanted to move all of what I'd done on the main timeline into a Movie Clip. Now most things don't work.

    I'm guessing that the things in the class were 'linking' or 'referring' to things on the main scene 1 stage which are now in a movie clip.

    I've tried to fix it but haven't had any luck. I'm getting errors like:
    TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display:isplayObject/_hitTest()
    at flash.display:isplayObject/hitTestObject()
    at DragDrop/drop()
    I'm uploading the two class files and the fla file for a clearer picture of what is happening. I'll also upload the working versions before I moved it into a movie clip.

    I've moved it into a movie clip as I want to have the same pieces of action happening multiple times and guessed this was the best way... Is it?

    Thanks for your time.

    draganddrop - working.fladraganddrop.fla

    Can we not upload class files? Here they are:
    https://dl.dropbox.com/u/309502/flash/flash.rar

    Map class file:

    Code:
    package 
    {
    
    	import flash.display.*;
    	import flash.events.*;
    	
    
    	public class Map extends MovieClip
    	{
    		var dragdrops:Array;
    		var numOfMatches:uint = 0;
    		var speed:Number = 25;
    
    		public function Map()
    		{
    			//constructor code
    			dragdrops = [red1,blue1,blue2,yellow1,green1];
    			var currentObject:DragDrop;
    			for(var i:uint = 0; i < dragdrops.length; i++)
    			{
    				currentObject = dragdrops[i];
    				currentObject.target = getChildByName(currentObject.name + "_target");
    			}
    			
    		}
    		
    		public function match():void
    		{
    			numOfMatches++;
    			if(numOfMatches == dragdrops.length)
    			{
    				win.addEventListener(Event.ENTER_FRAME, winGame);
    			}
    		}
    		function winGame(event:Event):void
    		{
    			win.y -= speed;
    			
    			if(win.y <= 0)
    			{
    				win.y = 0;
    				win.removeEventListener(Event.ENTER_FRAME, winGame);
    				win.addEventListener(MouseEvent.CLICK, clickWin);
    			}
    		}
    		
    		function clickWin(event:MouseEvent):void
    		{
    			win.removeEventListener(MouseEvent.CLICK, clickWin);
    			win.addEventListener(Event.ENTER_FRAME, animateDown);
    			
    			var currentObject:DragDrop;
    			for(var i:uint = 0; i < dragdrops.length; i++)
    			{
    				currentObject = dragdrops[i];
    				//getChildByName(currentObject.name + "_target").alpha = 0;
    				
    				currentObject.visible = true;
    			}
    			numOfMatches = 0;
    			addChild(win);
    			
    			
    		}
    		function animateDown(event:Event):void
    		{
    			win.y += speed;
    			
    			if(win.y >= stage.stageHeight)
    			{
    				win.y = stage.stageHeight;
    				win.removeEventListener(Event.ENTER_FRAME, animateDown);
    			}
    		}
    	}
    
    }
    DragDrop class file:
    Code:
    package 
    {
    	import flash.display.*;
    	import flash.events.*;
    	
    	public class DragDrop extends Sprite
    	{
    		var origX:Number;
    		var origY:Number;
    		var target:DisplayObject;
    
    		public function DragDrop()
    		{
    			// constructor code
    			//origX = x;
    			//origY = y;
    			addEventListener(MouseEvent.MOUSE_DOWN, drag);
    			buttonMode = true;
    		}
    		
    		function drag(evt:MouseEvent):void
    		{
    			stage.addEventListener(MouseEvent.MOUSE_UP, drop);
    			startDrag();
    			parent.addChild(this);
    		}
    		function drop(evt:MouseEvent):void
    		{
    			stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
    			stopDrag();
    			
    			if(hitTestObject(target))
    			{
    				visible = false;
    				//target.alpha = 1;
    				Object(parent).match();
    			}
    			
    			//x = origX;
    			//y = origY;
    		
    		}
    			
    	}
    
    }


    Thanks again.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    target is null. Replace "target" with "this" and it works. Also change Object(parent).match(); to Object(parent).match;
    since match is not a function.
    Last edited by cancerinform; 01-03-2013 at 02:38 PM.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks but I'm now getting this error:
    Map.as, Line 22 1084: Syntax error: expecting identifier before this.
    For this line: currentObject.this = getChildByName(currentObject.name + "_target");

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Make the changes only in DragDrop.as but not in Map.as.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Ok, have done that. Now getting this error:
    DragDrop.as, Line 10 1084: Syntax error: expecting identifier before this.

    Line 10: var thisisplayObject;

    And also these errors:

    Map.as, Line 1 5000: The class 'Map' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    DragDrop.as, Line 1 5000: The class 'DragDrop' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    DragDrop.as, Line 1 5000: The class 'DragDrop' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    DragDrop.as, Line 1 5000: The class 'DragDrop' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    DragDrop.as, Line 1 5000: The class 'DragDrop' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.

    Nothing is dragable either!

    Thanks.

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Just get back to the original class and then change
    if(hitTestObject(target))
    to
    if(hitTestObject(this))
    You can delete the line var targetisplayObject;
    That line was nonsense from the beginning, because target was not defined in that class. That is why it gave null.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    21
    Thanks! Now I'm getting these errors:

    C:\Users\Joe\Documents\Flash\Map.as, Line 17 1120: Access of undefined property red1.
    C:\Users\Joe\Documents\Flash\Map.as, Line 17 1120: Access of undefined property blue1.
    C:\Users\Joe\Documents\Flash\Map.as, Line 17 1120: Access of undefined property blue2.
    C:\Users\Joe\Documents\Flash\Map.as, Line 17 1120: Access of undefined property yellow1.
    C:\Users\Joe\Documents\Flash\Map.as, Line 17 1120: Access of undefined property green1.
    C:\Users\Joe\Documents\Flash\Map.as, Line 22 1119: Access of possibly undefined property target through a reference with static type DragDrop.

    Line 17: buttonMode = true;

    Line 22: stage.addEventListener(MouseEvent.MOUSE_UP, drop);

    Thanks

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center