2 Attachment(s)
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:
Quote:
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/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.
Attachment 74021Attachment 74023
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.