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 > General Help > Games

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-22-2006, 12:27 PM   #1
MarkSensei
Senior Member
 
Join Date: May 2006
Posts: 119
Code translation please

I was reading through a tute on collission detection and I found what I think Im looking for. ( detecting collission when an object is in a "drag' status)

but I dont understand it....its slash syntax...I'm a newbie to dot sytax!! I'm not certain what all these become in MX 2004. could anyone translate for me?

this is a quote from the tute:
Code:
7. Now in the first frame of your ENEMY movie, enter the following code:

flag = this.hitTest("/ship"); if (flag == true) { tellTarget ("/") { gotoAndStop
 ("hit"); } } You do this by selecting setVariable from the Actions menu. Then in the Variable section, enter: flag 

and in the in the Value section, enter: this.hitTest("/ship")

8. Then after that line of code, enter the following:

if (flag == true) { tellTarget ("/ship") { gotoAndStop (2); } } This is the code that will tell your ship movie to explode upon collision.

9. That's really all there is to it! Have fun!
This is what I was working with before I went searching. I have this on my drag object

Code:
on(press){
	startDrag(this);
	if(_root.pin.hitTest(_root.balloon)){
		_root.balloon.balloon2.gotoAndPlay("popped");
	}
}

on(release){
	stopDrag();
	}
this code works if I have the if statement on the RELEASE event, but not on the drag event.......

I hope thats enough explanation.

Thank you in advance for any help

Mark
MarkSensei is offline   Reply With Quote
Old 06-22-2006, 01:08 PM   #2
WilloughbyJackson
Patron Saint of Beatings
 
WilloughbyJackson's Avatar
 
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
Well, basically it's because the onPress/onRelease event only happens once.

I recommend doing something like this (NOTE: I'm assuming this code is from a button inside of a movie clip):

code:

on(press){
startDrag(this);
this.onMouseMove = function(){
if(_root.pin.hitTest(_root.balloon)){
_root.balloon.balloon2.gotoAndPlay("popped");
}
}
}

on(release){
stopDrag();
this.onMouseMove = undefined
}




EDIT: Oh yeah. / = _root

Last edited by WilloughbyJackson; 06-22-2006 at 01:30 PM.
WilloughbyJackson is offline   Reply With Quote
Old 06-22-2006, 01:33 PM   #3
MarkSensei
Senior Member
 
Join Date: May 2006
Posts: 119
Cool! it worked! now I want to ask, what is it? could you break it down for me? And maybe what some common application of this are? I feel as if this will be an important function.

Thank you very much

Mark
MarkSensei is offline   Reply With Quote
Old 06-22-2006, 02:29 PM   #4
WilloughbyJackson
Patron Saint of Beatings
 
WilloughbyJackson's Avatar
 
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
Well, this is basically a drag and drop routine if you need to check something while dragging.

To break it down:
code:

on(press){
startDrag(this);
//This creates a function watch for onMouseMove events. That means whenever the
//mouse is moved, whatever is inside of this function will occur.
this.onMouseMove = function(){
//For now, it is your hittest, however, you add as much code as you like in this statement.
if(_root.pin.hitTest(_root.balloon)){

_root.balloon.balloon2.gotoAndPlay("popped");

}

}

}



on(release){

stopDrag();
//Setting this.onMouseMove to undefined is erasing whatever checks were set up in
//onPress statement.

this.onMouseMove = undefined

}




I've used something like this for mouse based games before.
WilloughbyJackson is offline   Reply With Quote
Old 06-22-2006, 03:03 PM   #5
MarkSensei
Senior Member
 
Join Date: May 2006
Posts: 119
Ok, I think I understand that now. But I have one more question. Now I am trying to make a pin pop many balloons. my popped balloons have an animation for when they are popped. I found with this script I could pop a balloon, but if i kept moving the mouse, it would restart the animation. I corrected that by adding a

delete this.onMouseMove;

it worked for one MC.
now I have 4 balloons, when I pooped one, it would delete the onMouseMove so I could not pop any more.
I figured I would add the this.onMouseMove = function(); to the top of each if statement to see if it would work. now it will only pop the last balloon in my if statement.
I'm out of ideas......
here is what I have. (probably no very good)

Code:
on(press){
	Mouse.hide();
	startDrag(this, true);
this.onMouseMove = function(){
	if(_root.pin.hitTest(_root.r_balloon)){
		_root.r_balloon.gotoAndPlay("popped");
		delete this.onMouseMove
	}
	}
	this.onMouseMove = function(){
	if(_root.pin.hitTest(_root.b_balloon)){
		_root.b_balloon.gotoAndPlay("popped");
		_root.b_balloon._visible = false;
		delete this.onMouseMove
	}
	}
	this.onMouseMove = function(){
	if(_root.pin.hitTest(_root.g_balloon)){
		_root.g_balloon.gotoAndPlay("popped");
		delete this.onMouseMove
	}
	}
	this.onMouseMove = function(){
	if(_root.pin.hitTest(_root.p_balloon)){
		_root.p_balloon.gotoAndPlay("popped");
		delete this.onMouseMove
		}
            }
}
on(release){
	stopDrag();
this.onMouseMove = undefined
	}
MarkSensei is offline   Reply With Quote
Old 06-22-2006, 04:04 PM   #6
WilloughbyJackson
Patron Saint of Beatings
 
WilloughbyJackson's Avatar
 
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
First comment: You do not have to delete the onMouseMove after each hit test, you can just have the hit tests listed in sequence.

I.E.
code:

//...SNIP...
this.onMouseMove = function(){
if(_root.pin.hitTest(_root.r_balloon)){
_root.r_balloon.gotoAndPlay("popped");
}
if(_root.pin.hitTest(_root.b_balloon)){
_root.b_balloon.gotoAndPlay("popped");
_root.b_balloon._visible = false;
}
if(_root.pin.hitTest(_root.g_balloon)){
_root.g_balloon.gotoAndPlay("popped");
}
if(_root.pin.hitTest(_root.p_balloon)){
_root.p_balloon.gotoAndPlay("popped");
}
}
}
//...SNIP...



Or you could use an if else chain here.

However, to make things easier, this is where you would use For loops and concatenation.

First, rename your balloon movie clips to:
balloon_0
balloon_1
balloon_2
balloon_3

Next you would set up a for loop and use concatenation to check each
of the balloons.

Concatenation is the operation of joining two character strings end to end or a string and variable.

In otherwords if you have this:
code:

var i = 0

_root["balloon_"+i]



is exactly like saying this:
code:

_root.balloon_0



You follow me so far?

Okay..here's the example:
code:

//...SNIP...
this.onMouseMove = function(){
//FOR LOOP CODE IS LIKE THIS
//for (starting number;repeat this until this condition is no longer true;how
//the number will increase. ++ in Flash means it will increase by 1 for //each time through the loop.
for (var i = 0;i <= 3;i++){
if(_root.pin.hitTest(_root["balloon_"+i])){
_root["balloon_"+i].gotoAndPlay("popped");
}

}
}
//...SNIP...

WilloughbyJackson is offline   Reply With Quote
Old 06-24-2006, 12:20 AM   #7
MarkSensei
Senior Member
 
Join Date: May 2006
Posts: 119
sorry to take so long to get back to this thread. Thank you for the mini tute on for loops, I have read up on them before, but this has been the easiest to understand. I will definately make a n effort to get to know it better.


Thanks again

Mark
MarkSensei is offline   Reply With Quote
Old 06-24-2006, 01:39 AM   #8
WilloughbyJackson
Patron Saint of Beatings
 
WilloughbyJackson's Avatar
 
Join Date: Nov 2000
Location: Ro-cha-cha-cha, New York
Posts: 1,992
Not a problem.
WilloughbyJackson is offline   Reply With Quote
Old 06-24-2006, 12:41 PM   #9
MarkSensei
Senior Member
 
Join Date: May 2006
Posts: 119
i have another question about the onMouseMove function. I did what you said and put in a For loop with the If statement. But the problem stil remains where due to the onMouseMove, it triggers my drag objects animation every time the mouse is moved on the hitTest target making a very un-clean animation. Im trying to have the animation play only once per object... I have the fla. attached, the code is all over the place (I'm a newbie so I do what I can, so if anyone has some code clean up suggestions, feel free.) there is some code on the frame labeled "splat" that I tried to write on the first frame with an onEnterFrame event handler, but it didn't work. so I put the code on the objects (the frame is about 3 levels deep if you go looking for it) and the little red box is just a timer to end the sequence (its part of a bigger quiz game) the box is usually not visible, but I did this so it could be found.
Anyways, i know its a total mess, but its really the best i can do....
Thanks for all the help
....wow, just uploaded the Fla, dont know why its so big. it was only 16k when it was a frame of my quiz game..strange
Attached Files
File Type: fla flySwatting.fla (224.0 KB, 5 views)
MarkSensei is offline   Reply With Quote
Old 06-26-2006, 02:54 PM   #10
dawsonk
:
 
Join Date: Dec 2002
Posts: 2,557
Maybe try something like this...

Code:
onClipEvent (load) {
	for (var i = 0; i<=5; i++) {
		_root["fly_"+i].splat = false;
	}
}
on (press) {
	Mouse.hide();
	startDrag(this, true);
	this.onMouseMove = function() {
		for (var i = 0; i<=5; i++) {
			if (_root.fly_swatter.mesh.hitTest(_root["fly_"+i]) && _root["fly_"+i].splat == false) {
				_root.fly_swatter.gotoAndPlay("swat");
				_root["fly_"+i].splat = true;
				_root["fly_"+i].fly2.gotoAndStop("splat");
			}
		}
	};
}
on (release) {
	stopDrag();
	this.onMouseMove = undefined;
}
dawsonk is offline   Reply With Quote
Old 06-27-2006, 01:43 PM   #11
MarkSensei
Senior Member
 
Join Date: May 2006
Posts: 119
OK, that worked great! Thank you
I'm wondering if I could run by what I understand this script to be saying and could you tell me if im right or not. I'm still new to this so Im interested to know.

Quote:
onClipEvent (load) {
for (var i = 0; i<=5; i++) {
_root["fly_"+i].splat = false;
}
setting a all the flys booleen to false.

Quote:
for (var i = 0; i<=5; i++) {
if (_root.fly_swatter.mesh.hitTest(_root["fly_"+i]) && _root["fly_"+i].splat == false) {
_root.fly_swatter.gotoAndPlay("swat");
_root["fly_"+i].splat = true;
_root["fly_"+i].fly2.gotoAndStop("splat");
we are now watching the flys and waiting to the IF condition to be met. The condition is IF the swatter is on a fly AND if the fly's booleen is false (meaning it hasn't been squashed) then swat the fly, change its booleen to true so that it can no longer trigger the animation and stop the playhead on the sqwashed fly anim.

Thanks so much. I think I learnt something new here.
MarkSensei is offline   Reply With Quote
Old 06-27-2006, 05:19 PM   #12
dawsonk
:
 
Join Date: Dec 2002
Posts: 2,557
Yes, that's exactly it!
dawsonk is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Games

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 03:05 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.