To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 05-31-2006, 07:42 AM   #1
ukspudnie
Senior Member
 
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
Hit Testing my newest challenge...!!

Hi guys

i'm using a motion dection system to control an interface and instead of doing each hit test on it's own i wanted a function which would make it simplier to code... instead of righting a million and 1 if statements..

Well this isn't producing any errors but i'm sure it's wrong because it's not working...so i'm just checking in with you guys to see if i'm writing my hit tests and variables right... the hover function needs to relate to what ever i call it in the paramaters when i call the function... anyhelp would be most grateful..

Andy


Code:
 

//HIT-TESTFUNCTIONS

function hitAndHover(target,hover):Void{
		var hover:Number=0;
	if (trackdot.hitTest(target)){
		hover++;
		target.gotoAndPlay("OverState");
		trace(hover);
		
	}else{
		target.gotoAndPlay("NormalState")
		hover=0;
	}
};

//Activation Function

function Thumbs_hitAndPlay(target,sName,sPos):Void{
	if (hover==20) {
		_root.populateCONTENT(sName,sPos);
		target.gotoAndPlay("Selected");
		trace("Activated");
		hover=0;
	}

};

//CALLING THE FUNCTIONS.. THESE ARE ON THE TIME LINE WHERE THEY ARE MEANT TO ACTIVATE IN THIS CASE INSPIRE.. 

//THUMB1
//Here i'm trying to tell it to in laymans terms.. if trackdot (which is the movie clip which is moved via motion detection) hits thumb1 start counting hover1

_root.hitAndHover(thumb1_mc,hover1);

//Here i'm trying to tell it to in laymans terms again to if trackdot has hit thumb1 for hover1 count 20 then activate function populateContent with the 
Inspire array at 0.

_root.Thumbs_hitAndPlay(hover1,thumb1_mc,"Inspire",0);

//THUMB2

_root.hitAndHover(thumb2_mc,hover2);
_root.Thumbs_hitAndPlay(hover2,thumb2_mc,"Inspire",1);

//THUMB3

_root.hitAndHover(thumb3_mc,hover3);
_root.Thumbs_hitAndPlay(hover3,thumb3_mc,"Inspire",2);

//THUMB4

_root.hitAndHover(thumb4_mc,hover4);
_root.Thumbs_hitAndPlay(hover4,thumb4_mc,"Inspire",3);

//THUMB5

_root.hitAndHover(thumb5_mc,hover5);
_root.Thumbs_hitAndPlay(hover5,thumb5_mc,"Inspire",4);

//THUMB6
_root.hitAndHover(thumb6_mc,hover6);
_root.Thumbs_hitAndPlay(hover6,thumb6_mc,"Inspire",5);
ukspudnie is offline   Reply With Quote
Old 05-31-2006, 10:35 AM   #2
ukspudnie
Senior Member
 
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
Update well i've tried a few new things but still no luck... any ideas?
ukspudnie is offline   Reply With Quote
Old 05-31-2006, 03:41 PM   #3
ukspudnie
Senior Member
 
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
UPDATE : STILL NOT WORKING the bummer although the code is a lot cleaner now.. but i still don't understand what i'm doing wrong...

here is the whole code.. including the motion tracking code

Code:
//Motion tracker

import flash.display.*;
import flash.geom.*;
// INIT
trackdot.inTrans = false;
setInterval(detection, 110);
ScreenSizeX = 800.0;
ScreenSizeY = 480.0;
// Connect the webcam

cam = Camera.get();
this.vid.attachVideo(cam);


now = new BitmapData(cam.width, cam.height);
before = new BitmapData(cam.width, cam.height);
rect = new Rectangle(0, 0, cam.width, cam.height);
trace("cam.width="+cam.width+" cam.height="+cam.height);
sizeDif = ScreenSizeX / cam.width;

pt = new Point(0, 0);
// Show The MonoColor image
//coverRect = new Rectangle(0, 0, 130, 120);
function detection() {
	if (!cam.muted) {
		now.draw(vid);
		now.draw(before, new Matrix(), new ColorTransform(), 'difference');
		now.threshold(now, rect, pt, '>', 0xff333333, 0xffff0000);
		now.fillRect(coverRect, 0xff000000);
		before.draw(vid);
		// 
		re = now.getColorBoundsRect(0xffffffff, 0xffff0000, true);
		//trace(r.toString());
		ColorChange = now.threshold(now, re, new Point(re.x, re.y), '==', 0xffff0000, 0xffff0000);
		//trace(ColorChange);
		if (re.x<160 && ColorChange>10) {
			trackdotNewY = (re.height/2+re.y)*sizeDif;
		}
		if (re.y<120 && ColorChange>10) {
			trackdotNewX = re.width/2+re.x;
			trackdotNewX = ScreenSizeX-(trackdotNewX*sizeDif);
		}
		tweenPlayer(trackdotNewY, trackdotNewX);
	}
}
// display the motion detection bitmap
bitmaporb_mc.attachBitmap(now, 10);

vx = 75;
vy = 75;
//r = tackdot._width/2;


//HIT-TESTFUNCTIONS

function hitAndHover(target, hover):Void {
	_root[hover] = 0;
	if (trackdot.hitTest(target)) {
		_root[hover]++;
		target.gotoAndPlay("OverState");
		trace("Hovertimer"+_root[hover]);
	} else {
		target.gotoAndPlay("NormalState");
		_root[hover] = 0;
		trace("NOT..HOVER");
	}
}

function Thumbs_hitAndPlay(target,hover,sName,sPos):Void{
	if (_root[hover]==20) {
		_root.populateCONTENT(sName,sPos);
		target.gotoAndPlay("Selected");
		trace("Activated");
		_root[hover] = 0;
	}

};

function tweenPlayer(param, param2) {
	easeType = mx.transitions.easing.Regular.easeOut;
	
var mc = trackdot;
	if (mc.inTrans == false) {
		
		//mc.inMovement = true;
		var begin = mc._y;
		var beginX = mc._x;
		var end = param;
		//var end = mc._y+(random(10)-5);
		var time = 0.6;
		ballTween = new mx.transitions.Tween(mc, "_y", easeType, begin, end, time, true);
		ballTween = new mx.transitions.Tween(mc, "_x", easeType, beginX, param2, time, true);
		ballTween.onMotionFinished = function() {
			mc.inTrans = false;
		};
	}
}
Right that should deal with any hit tests on the thumbnails in the two functions...

Now here is where the function are called.. in a sep frame on the inspire marker..

Code:
stop();
//INIT
_root.populateInspireThumbs();


//CALL FUNCTIONS IN INSPIRE FRAME

//THUMB1
onEnterFrame=hitAndHover(thumb1_mc,"hover1");
onEnterFrame=Thumbs_hitAndPlay(thumb1_mc,"Inspire",0);

//THUMB2
onEnterFrame=hitAndHover(thumb2_mc,"hover2");
onEnterFrame=Thumbs_hitAndPlay(thumb2_mc,"Inspire",1);

//THUMB3
onEnterFrame=hitAndHover(thumb3_mc,"hover3");
onEnterFrame=Thumbs_hitAndPlay(thumb3_mc,"Inspire",2);

//THUMB4
onEnterFrame=hitAndHover(thumb4_mc,"hover4");
onEnterFrame=Thumbs_hitAndPlay(thumb4_mc,"Inspire",3);

//THUMB5
onEnterFrame=hitAndHover(thumb5_mc,"hover5");
onEnterFrame=Thumbs_hitAndPlay(thumb5_mc,"Inspire",4);

//THUMB6
onEnterFrame=hitAndHover(thumb6_mc,"hover6");
onEnterFrame=Thumbs_hitAndPlay(thumb6_mc,"Inspire",5);
Can anyone tell me why this isn't working... because it's drivin me nuts...

Andy.
ukspudnie is offline   Reply With Quote
Old 05-31-2006, 05:27 PM   #4
ukspudnie
Senior Member
 
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
Update.. Still Stuggling... But getting there will keep reporting on progress.
ukspudnie is offline   Reply With Quote
Old 05-31-2006, 10:23 PM   #5
ukspudnie
Senior Member
 
Join Date: Nov 2004
Location: I'm a brumie, currently in London working for the man
Posts: 147
update.. it's gonnabe a long night to get this done....

.got the hit testing working now ya... it's not great but it's getting there.. even got roll over states working 2..still it's gonna be a long night 2night ... want to get the video player finished at least..

Andy
ukspudnie is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:03 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.