Jump to content


How to make this code work the way I want it to?


  • You cannot reply to this topic
11 replies to this topic

#1 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 02 August 2006 - 11:18 PM

A button when clicked, will initialize a movie clip (bg) to move. When bg hits a target (lb1), hit test would detect and stop bg. However, if hit test cannot detect bg hitting target, bg will continue to move.

on (release) {
	_root.bg._y = _root.bg._y-5;
	if (_root.bg.hitTest(_root.lb1) == true) {
		_root.bg._y = _root.bg._y+5;
	}
	if (_root.bg.hitTest(_root.lb1) == false) {
		_root.bg._y = _root.bg._y-5;
	}
}

How to make this code work?

Edited by cng, 02 August 2006 - 11:19 PM.


#2 adzicents

    Young Padawan

  • Members
  • Pip
  • 21 posts
  • Location:Melbourne, Australia

Posted 02 August 2006 - 11:28 PM

on (release) {
	_root.bg._y = _root.bg._y-5;
	if (_root.bg.hitTest(_root.lb1) == true) {
		_root.bg._y = _root.bg._y+5;
	} else {
		_root.bg._y = _root.bg._y-5;
	}
}

Try that, should work. Changed the second if statement to an else and so this should work better, let alone at all :(

Edited by adzicents, 02 August 2006 - 11:28 PM.


#3 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 03 August 2006 - 12:12 AM

View Postadzicents, on Aug 3 2006, 04:27 AM, said:

on (release) {
	_root.bg._y = _root.bg._y-5;
	if (_root.bg.hitTest(_root.lb1) == true) {
		_root.bg._y = _root.bg._y+5;
	} else {
		_root.bg._y = _root.bg._y-5;
	}
}

Try that, should work. Changed the second if statement to an else and so this should work better, let alone at all :(

Nope. It's still -5 per click. The 'else' didnt work. It doesnt continue...

#4 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 03 August 2006 - 01:21 AM

This code will not work, because your button just shoots the code once out, and since the condition doesn't apply the movie stops. I assume you still want to do that elevator thing?

#5 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 03 August 2006 - 01:23 AM

Hehe, yes. I still do and I thought if I can make it go and stop then it'd be fine. Is there a way for me to make this continue to go? By any chance you have MSN?

#6 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 03 August 2006 - 01:28 AM

I assume you want something like this?
http://kirupa.com/de...slidingMenu.htm

#7 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 03 August 2006 - 01:31 AM

Thanks, buddy! You're magical. I never know how to search because I dont know proper terms. Sliding menu, that is so nice! Anyways, if you got MSN, pm me and I'll add you. A noob like me needs a pro to be guided around.

#8 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 03 August 2006 - 02:01 AM

After attempting the code with my exsisting project. Nothing happens at all. Maybe Im too dumb to understand the concept of the code but I replaced all the variables with the right instance names. I tried both with _x and _y (as my menu goes up and down) but neither worked. I need some tips on what I did wrong.

#9 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 03 August 2006 - 02:05 AM

send me the url to your fla so I can have a look at it.

#10 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 03 August 2006 - 02:20 AM

Do you have MSN? Or else I'd have to send to you via email.

#11 bezz

    Young Padawan

  • Members
  • Pip
  • 23 posts
  • Gender:Male
  • Location:Berlin, NJ
  • Interests:Flash, Snowboarding, Paintball, Learning Guitar

Posted 03 August 2006 - 01:11 PM

This may be the problem.
bg and lb1 are movie clips right? Well in order to use hitTest, you need to create instances of those movie clips. Doing that is simple, and you can name an instance the same name as the movie clip itself.
Attached File  instance.gif   16.7K   102 downloads

#12 cng

    Young Padawan

  • Members
  • Pip
  • 55 posts

Posted 03 August 2006 - 06:05 PM

Thanks for the reply bezz but that is not the problem. I've named the instances. The problem could be because I have them too deep. They are in a movieclip, which are in a movieclip, which is in the middle of the timeline of that movie clip.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users