473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Hit Test

hi friends,

i have a problem with this code. when i run this code, i want that the arrow should not accross the wall movieclip but it is accrossing the wall.

So if anyone have some idea about what we can do for to get the desired result.

thaks



my FLA file code:

var myclass:moveArray = new moveArray(arrow_mc);


As files code:


class moveArray extends MovieClip {
var targetMc:MovieClip;
var mc:MovieClip;
var wall:MovieClip;
//var myListener:addEventListener;
public function moveArray(targetMc:MovieClip) {
//trace(targetMc);
this.targetMc = targetMc;
checkPosition(targetMc);
updatePosition(targetMc);
}
//-------------------------------------------------------------------
public function updatePosition(mc:MovieClip) {
var myListener:Object = new Object();
myListener.onKeyDown = function() {
if (Key.isDown(Key.RIGHT)) {
//trace("right key is pressed");
//trace(mc);
mc._rotation = 90;
mc._x += 25;
}
if (Key.isDown(Key.LEFT)) {
//trace("left key is pressed");
mc._rotation = -90;
mc._x -= 25;
}
if (Key.isDown(Key.UP)) {
//trace("up key is pressed");
mc._rotation = 360;
mc._y -= 25;
}
if (Key.isDown(Key.DOWN)) {
//trace("down key is pressed");
mc._rotation = 180;
mc._y += 25;
}
};
Key.addListener(myListener);
}
//------------------------------------------------------------
public function checkPosition(mc:MovieClip) {
mc.onEnterFrame = function() {
if (this._x>=Stage.width) {
//trace("right");
this._x = Stage.width-this._height/2;
}
if (this._x<=0) {
this._x = this._height/2;
}
if (this._y<=0) {
this._y = this._height/2;
}
if (this._y>=Stage.height) {
this._y = Stage.height-this._height/2;
}
};
}
public function chkcoll(mc:MovieClip, obj:Object) {
if (mc.hitTest(obj)) {
// this._y = 249;

}
}
}
Aug 13 '07 #1
1 1823
hmmm.. i could use some clarification on your exact problem, i didnt really get what you meant. few pointers, however.
1. it looks like you are commenting out your traces for run-time, ect. just fyi, under publish settings, flash tab, you can check not to export traces. this will lower your bandwidth a little, and allow you to put in as many traces as you want without worrying.

2. right here.. "if (this._x>=Stage.width) { this._x = Stage.width-this._height/2;} " it looks likt you are trying to say "if i am off the right side, move me to the middle of the stage(not the middle of the mc, is what i think you are going for). however, you are looking at the height, not the ._x characteristic, the width. try something simpler, like this._x = Stage.width/2;

3. when you are inside a function () { }, using "this" references whatever called the function, so mc_instance.OnRollover = function () { this.gotoAndPlay(1);} is going to go to and play frame one of our mc_instance. if you want to be in reference to the frame you are on (aka if you want to control a different movie clip), just leave out the "this" and it will be in relation to the current frame

hope that helps

crabpot8



hi friends,

i have a problem with this code. when i run this code, i want that the arrow should not accross the wall movieclip but it is accrossing the wall.

So if anyone have some idea about what we can do for to get the desired result.

thaks



my FLA file code:

var myclass:moveArray = new moveArray(arrow_mc);


As files code:


class moveArray extends MovieClip {
var targetMc:MovieClip;
var mc:MovieClip;
var wall:MovieClip;
//var myListener:addEventListener;
public function moveArray(targetMc:MovieClip) {
//trace(targetMc);
this.targetMc = targetMc;
checkPosition(targetMc);
updatePosition(targetMc);
}
//-------------------------------------------------------------------
public function updatePosition(mc:MovieClip) {
var myListener:Object = new Object();
myListener.onKeyDown = function() {
if (Key.isDown(Key.RIGHT)) {
//trace("right key is pressed");
//trace(mc);
mc._rotation = 90;
mc._x += 25;
}
if (Key.isDown(Key.LEFT)) {
//trace("left key is pressed");
mc._rotation = -90;
mc._x -= 25;
}
if (Key.isDown(Key.UP)) {
//trace("up key is pressed");
mc._rotation = 360;
mc._y -= 25;
}
if (Key.isDown(Key.DOWN)) {
//trace("down key is pressed");
mc._rotation = 180;
mc._y += 25;
}
};
Key.addListener(myListener);
}
//------------------------------------------------------------
public function checkPosition(mc:MovieClip) {
mc.onEnterFrame = function() {
if (this._x>=Stage.width) {
//trace("right");
this._x = Stage.width-this._height/2;
}
if (this._x<=0) {
this._x = this._height/2;
}
if (this._y<=0) {
this._y = this._height/2;
}
if (this._y>=Stage.height) {
this._y = Stage.height-this._height/2;
}
};
}
public function chkcoll(mc:MovieClip, obj:Object) {
if (mc.hitTest(obj)) {
// this._y = 249;

}
}
}
Aug 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Berthold Hoellmann | last post by:
Hello, When I use ./configure --with-thread --with-fpectl --with-signal-module \ --with-pymalloc --enable-shared --with-cxx=g++ make test on 2.3.3 I get
0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
4
by: Edvard Majakari | last post by:
Hi, I just found py.test and converted a large unit test module to py.test format (which is actually almost-no-format-at-all, but I won't get there now). Having 348 test cases in the module and...
0
by: Andrea M. Segovia | last post by:
I just compiled (but did not install) perl 5.8.0 on an SGI Origin 300 server (IP35) running IRIX 6.5.20m. Make test reported one test error, which I narrowed down to .../lib/ExUtils/t/Constant.t...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.