ActionScript 3.0 :: Flash Hittest Only Works On Last Object In Array
Mar 24, 2012
For days now I have been trying to get this hit test to work and which ever way I try it, it always comes back to the same result. I get a hit on the last item I pushed into my array but none on the previous items I pushed in. Also if I put a .sort() on the array it only gives a hit on the last item of the array, no matter which one I push in.
The idea is that I want to drag and drop objects onto the stage, they may not overlap so I need a hit test on the objects so I can make them undroppable when the hit test is true.
This is the part I have for dragging the objects to the stage, and adding them to arrays for the hit test.
Code:
private function onClickDragBuilding1ToGameField(e:MouseEvent):void{
building1Placeholder.x = mouseX-25;
building1Placeholder.y = mouseY-25;
[Code]...
Now if I run this I can add the object to the stage just fine no errors or other issues but the hit test only works on the last object I added to the stage/array and not the previous object I added to the stage/array.
Sso I drag the first object to the stage. (no other object are available yet so nothing happens, this is as it should be) Then I drag a second object to the stage, this reacts to the first object and returns the hit test as true. (Also great and working as it should.) Then I drag a 3th object to the stage, this reacts to the 2nd object I dragged just fine and return a true value, but it does not react to the 1 object I dragged onto the stage. Then when I drag a 4th object to the stage it will react to the 3th object I added, but not the 1st ad 2nd object.
View 4 Replies
Similar Posts:
Mar 15, 2011
I have a function that checks if 2 objects are touching OB1 and OB2, if they do touch it runs the rest of the collision code where OB1 is the character and OB2 is a tile that the player cannot pass through.
I came across an issue where i wanted sprites to be separate from the hitboxes but my collision code works by checking the height and width of an object (you guys know the drill).
So i have a Tile class with 2 parts to it, a bitmap and a movieClip.
So i have this setup(pseudocode):
Code:
loop
{
function collision (ob1 , ob2[loop].movieclip)
}
This should work right? But it ONLY works for the first object in the loop!
View 4 Replies
Apr 6, 2010
I was using hitTest to see when sunny (mc) would hit one of five objects I have in an array. But I had to use removeEventListener otherwise it would keep occurring. But now I can't "hit" the next object. Why doesn't the addeventListener work again?
stage.addEventListener(MouseEvent.CLICK, myClickReaction);
// speeds ALONG NYPOTENUSEvar v:Number=5;
var varObject:String;
var i:Number;
var arrayObjects:Array;
[Code] .....
View 4 Replies
Dec 5, 2009
adding multiple childs to an array these childs are added using timer after a time interval.actually there two classes and child of both classes are added to stage one through timer as i described and other through keyboard event. now is it possible to do this if yes than how?? and is it possible to apply hittest object between these two array.
View 6 Replies
Oct 14, 2011
I've attached a zip with a few custom classes and a .FLA. Ignore the custom classes. I'm getting repeated
"Error #1009: Cannot access a property or method of a null object reference. at Environment_fla::MainTimeline/hitTest()".
I understand that this error means I'm asking it to reference something that's no longer there. How better to hitTest many objects in an array. My game involves creating a bunch of balls that will fall into buckets. I need to keep track of how many touched the buckets, how many fell off the screen, and remove each accordingly.
Here is the code from my main FLA
ActionScript Code:
var ballTimer:Timer = new Timer(200);
var changeTimer:Timer = new Timer(50000);
ballTimer.addEventListener(TimerEvent.TIMER, throwBall, false, 0, true);
ballTimer.start();
changeTimer.addEventListener(TimerEvent.TIMER, changeColor);
changeTimer.start();
[Code] .....
View 6 Replies
Mar 20, 2012
regarding adding multiple childs to an array these childs are added using timer after a time interval.actually there two classes and child of both classes are added to stage one through timer as i described and other through keyboard event. now is it possible to do this if yes than how?? and is it possible to apply hittest object between these two array.
View 6 Replies
Jan 26, 2010
when i make this script:
onEnterFrame = function(){
if(ss.hitTest(_root.c2)){
_root.ss._x = -49.4;
}
}
it only does go to cords -49.4 once, after ss have hit c2 once it doesn't react when it hits c2 again!
View 9 Replies
Sep 5, 2009
Perhaps I should leave well enough alone, but it bugs me that my hitTest gives me an error message even though it seems to work as intended. I have two movieClips running side by side. The second clip, the hitTest object is actually in an array that I keep pushing every second.
[Code]...
I have tried to trace cars[i].name and it returns "instance XXX" instead of what I would have expected, which would have been something like cars1, cars2, etc... If that is creating the error, I don't know how to fix it. I have thought also that perhaps the array itself is being referenced, but again I wouldn't know how to change it.
View 11 Replies
Oct 14, 2003
My hitTest function only works on the y-axis
This is the code....
onClipEvent (enterFrame) {
// _root.speed = speed;
if (Key.isDown(Key.UP)) {
speed += 3;
[Code] .....
View 1 Replies
Dec 29, 2009
How would i make hitTest work better with a rotating object(AS2). Becase i have a circle and it if gets near the rotating object (actually pretty far away) it starts the script,(new x and y)
I think thats the rotation script, becuase i took a break for like 4 days becuase it was irritating.
View 1 Replies
Feb 27, 2012
I have a problem with the getChildIndex() method. I have an array that stores multiple children and I want to perform a hitTest that only works on children with a certain depth, with one that is lower than the other hitTest "partner". Therefore I want to check the depth of that certain child.I tried to trace the depth, but I get crazy errors doing that. No matter if I do it from the child itself, or from the Document Class.
trace(getChildIndex(foes[7][1][1]))
[7] is the current level, [1] is the type of child and the second [1] is the child itself called [Object EnGob]. I put it there by the push() command.
View 3 Replies
Jan 21, 2004
Ive got a code to move a MC on the main stage together with the mouse, in the the X axis,. difficult to explain. But now the client wants that this MC movement works only when the Y position of the mouse is over the 300 px. I thought I need a hit test or something elese. Please help. Here is the whole code.
[Code]....
View 1 Replies
Apr 6, 2011
I am working on an application where an image serves as cursor. Now i would like to know at any time over which object the cursor is hovering. Sort of like a HitTestObject(*) where i can then see what object the * represents. how i could accomplish this? (and using the mouse is not an option)
View 2 Replies
Aug 23, 2011
I have converted a PNG into a bitmap, then converted that into bitmapData.
I have a object called _player, and I wish to add collision detection, however I can seem to get it to work.
my code is:
if(bmd1.hitTest(new Point(_player.x, _player.y))){
trace("hit");
}
bmd1 is my bitmapData,_player is the object is wish to test against.
I am getting the following error:
1136: Incorrect number of arguments, Expected 3
I have looked around but cannott find what argument I am missing
I have tried
if(bmd1.hitTest(new Point(_player.x, _player.y), 50, _player)){
trace("hit");
}
I should mention that the reason for me taking this approach is that I have a PNG, with transparent areas, I need to test for collisions in the non-transparent areas, which is why I was using this approach
I have a PNG, i import that and convert to bitmap, then convert to bitmapData
View 3 Replies
Mar 20, 2009
The Setup: For each movieclip the hittests a set of "target" movieclips an array is given a value. If mcIcon1 is dropped onto mcTarget1 the first number in the vacant array is given the value of one. The Issue: If I remove mcIcon1, for example, from the mcTarget1 movieclip I can't find a way of just removing the 1 from that array without the rest of the array numbers being reset.
[Code]...
View 9 Replies
Jan 7, 2009
ok so if i have an obect called square1 and an object called square2 and inside square2 i have hitArea... i want to use shapeflag to detect an absolute true hitTest on just the area of square1 not the bounding box.... i tried this code and it didnt work...
actionscript 2.0
ActionScript Code:
if (_root.square1.hitTest(square2.hitArea._x, square2.hitArea._y, true)) {
View 2 Replies
Sep 19, 2011
The "modern" updated way to embed a flash object, according to Adobe:
[Code]...
Then it works on Firefox and Chrome (the AS function is called and works properly) - (it doesn't work in IE though). How come it doesn't work with an object tag? How "safe" it is to use the embed tag instead of the object tag? Is it not obsolete? Note, that it is definitely not a timing issue - If I call the AS function from JS from an onclick function - then the results are the same.
View 2 Replies
Jan 19, 2010
A simple flash video doesn't appear in IE. I've looked at answers to the same problem by NineBerry, however, I've tried those suggestions without luck.[code]I didn't include the file mulholland_intro_slideshow.fla as I doesn't seem necessary.I'm also aware that when encoding with Flash the object can only be made to played locally or via the network. I encoded locally for testing but it also plays across the network. Is that even relevant? I don't know.
View 1 Replies
Oct 14, 2011
I'm using a package to play back .wav files in Flash. I can make wav's play back, however, what I cannot do is trigger their playback from a button. I suspect this is because I've misunderstood the this keyword. Below is an example.
You can see that when I call playBackTest() directly it works; when I call this object from a button it doesn't.
[Code]...
View 1 Replies
Jul 13, 2010
I am curious if this is an okay implementation of the Array.filter() method.
[Code]...
I was not able to figure out an implementation of the callback function for the filter() method, where the callback was outside of the getGallery() function. I wonder if there is a way to get the isGallery function outside of the getGallery scope?
View 1 Replies
Jul 22, 2011
I have this thing where orbs are supposed to stick together, so I put them all in an arrayand told them to stick together when they encounter another member of that array.However, they only stick in groups of up to four, and then the orbs begin to overlap and such.
View 2 Replies
Oct 15, 2010
I'm making a game were parts of the level are randomly generated and move across the screen and while I have made it so all that works correctly I am having trouble running a hittest on them to allow for gravity. Below is the piece of code attached to the player movieclip that I think is causing the issue (shortened for sake of space)
[Code]...
View 3 Replies
Aug 10, 2003
I'm trying to make two duplicated movie clips check for any of the others ie bullet239 hitting badguy92
View 12 Replies
Feb 18, 2009
I am trying to use the following code to simplify multiple Hittests using an Array, but the code won't work. Can anyone tell me why?
var blockArray:Array = new Array("block1", "block2", "block3");
player.addEventListener(Event.ENTER_FRAME, blockTest);
function blockTest(evt:Event):void {
[Code].....
View 4 Replies
Jun 24, 2007
I've built an array of movieclips - all of them sitting static on the stage. I'm trying to trigger the clips to play as they are hit by an invisible/alpha 0 bar which sweeps across the stage... kind of like a mexican wave? I'm still a bit crappy with arrays - here's my code:
[Code]....
View 3 Replies
Feb 27, 2012
I would like to know if there's the way to do collision check on every object on the stage,
[Code]...
I want to make the object such that it falls on a rotated platform and land according to it's angle. I've success fully make it landed according to it's angle before it lands. but the problem here is that, after the landing when I trigger the rotating platform, the object falls when the platform is out of it's hit area. Is there a way such that it will work like a car wiper and wipe the object towards it's direction?
View 3 Replies
Jul 10, 2010
I'm coding a really simple 2D platforming game in Flash using AS3. I'd like to define two different types of terrain surfaces that the player can walk on based on classic platforming elements. Type1: the player can walk on, and if the player jumps, they will hit their head on it and bounce back to the ground. Type2: the player can also walk on, but if the player jumps and hits their head, they will simply pass through the surface and not bounce back to the ground.
I am using hitTestPoint to resolve collisions for this. My question is: What would be the best method to test for what TYPE of ground I am colliding with? Each ground type has it's own Class associated with it in my Flash IDE and all the different terrain surface types are in the same movie clip on the stage.
Currently I'm testing to see if it hit one type of ground surface, then i'm testing if it hit the other, and then based on those results, I process what I want to happen. This seems to work okay right now, but I'm imagining that I may want to create more than 2 types of ground to collide with. For example, moving platforms. It seems like the code will start to get complex
Eg.
if(_groundType1.hitTestPoint(_player.x, _player.y, true))
{
if(_groundType2.hitTestPoint(_player.x, _player.y, true))
[Code].....
View 1 Replies
May 26, 2010
My Question is how i deduct the position of the hitTest Objecti mean to say which angle he hit X Y and after hiting it must be goo that angle
here is my code
import mx.transitions.Tween;
import mx.transitions.easing.*;
[code]......
View 4 Replies
Jul 19, 2010
Is there a way that only allow hittest of a mc to hit one objects, if it hit multiple object it ignore it?
View 1 Replies
Dec 13, 2004
I have a simple FOR loop which runs through an array of MC names, which runs fine, but I'm trying to use these names inside this array as hittest values. So, I have one MC, and the code in this MC runs through an array and checks for any collisions between it and the mc in the array.
[Code]...
View 6 Replies