Actionscript 3 :: HitTestObject To A Specific Instance Within An Array?
Mar 12, 2012
I'm making a tile based game in AS3. Now I need to check a collision between the player and each tile (which are created in an array with 300-something instances).
I want to do that in my Main class. The player is in a class called Level and the tileArray is in another class. When I execute, I get the classic #2007 error - "Parameter hitTestObject must be non-null".
MAIN
public function checkCollision():void{
if(_level._tileSetBMP._tileArray[0] == null){
_level._tileSetBMP._tileArray[0] as flash.display.DisplayObject;
[Code].....
What can I do to make a hitTest with each of the [0]-instances of the array?
I got this rectangle_mc such that when I drag it to either the mask1_mc or mask2_mc, it will load movie_mc and plays it on the specific mask. But there's something wrong with my code.Here's the code:
Code: Select allimport flash.display.MovieClip; var movie_mc:MovieClip = new movie(); rectangle_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
I would like to detect a collision between a named MovieClip on the stage and an instance of a MovieClip from the Library which is created dynamically.
at the moment I'm putting all the dynamic instances in an Array and then I loop through all of them to see if I'm colliding with any of them, which I think is not great:
for each (var zz in corridors){ if((map_player.Ndist1.hitTestObject(zz) == true)&&(zz is brick)){ ...
I'd like to remove the loop and do the hit test and do something like
I'm creating randomly moving boxes. And when one box touches another one something happends. The code below is something i've done but the problem is that when the for loop goes trought the array the box hits itself.[code]
is there an easy way, using 1 or more for loops, to hit test every object in an array against every other object in that array. So I've got an array of 6 things
My hitTestObject fails even though a trace shows that I'm getting access to the correct target object.
I read a post that said that hitTestObject won't work if the hitter has the same identifier as other hitters (like in an array). So I tried using a single hitter (set the array to have only one element) and it does work, which makes me think I need to give a unique ID to each hitter in the array.
I can declare a string var in the for loop and make it unique, but since it's a string it won't accept being typed as another class.
how to create 100 unique var names that can be typed as a class?
Code: package{ import flash.display.Sprite; public class Liner extends Sprite{
I am wondering if it's better to pass an instance of a whole class to another class or just specific properties of that class. For example if I want the height property of class A in class B do I pass just the height value into class B or the whole instance of the class and use classA.height in class B?
I'm having a little trouble with the properties of an instance of a specific class. Here's and example of the code I am using:
Code: package { import flash.display.MovieClip; import flash.events.*; public dynamic class Circle1 extends MovieClip { private var _root:Object; [Code] .....
This is in the class code for Circle1. Now here is the error that is being displayed int he Output Box when I try to run the file: Code: TypeError: Error #1010: A term is undefined and has no properties. at Circle1/eFrame()
Here's the code that creates the two class instances as children on the Main Time Line: Code: if (spaceDown) { var newCircle1:Circle1=new Circle1(); addChild(newCircle1); } if (enterDown) { var newCircle2:Circle2=new Circle2(); addChild(newCircle2); } EnterDown is a defined variable for the key press of Enter, and spaceDown is a defined variable for the key press of Space.
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?
I have a class ErrorMessages which holds all my error messages as static constants. So I could access them like ErrorMessages.PASSWORD_INVALID or ErrorMessage.PASSWORD_TOO_SHORT. I want to know if it is possible to have separate classes that hold subset of these constants and access them like ErrorMessages.PASSWORD.INVALID or ErrorMessages.PASSWORD.TOO_SHORT, etc. This way I can more structured static structure and makes it much easier to use autocomplete. I tried few different ways and couldn't figure out if this was possible..
first time poster. Let's say a have flash(swf) object on my page, and I have a specific JavaScript class (lets call it "JSClass")that works with that flash object. JavaScript class has some methods for communicating with the flash object. When the flash object is embedded in to page via swfObject, I create an instance of the JSClass, and give it the id of the flash object on the page, so that instance can specifically communicate with that flash object. I have more than one same flash file on the page, and I need to differentiate calls to specific flash objects. Something like this:
[Code].....
How can I call "flashControl1.onFlashReady()" from flash? Note that flash doesn't know which JSCLass instance to target. How can target particular JSClass instances from flash object.
What I want to do is have one movieclip that has many frames and turn that into a button and then make different instances of the button and have those instances display a certain frame of the underlying movieclip.
I'm trying to get the name of every files from a specific folder into an array, but I get this error and I can't find why... TypeError: Error #1009: Cannot access a property or method of a null object reference.
Here's my code: import flash.filesystem.File; function getFileList(directory:String):Array { var folder:File = new File(directory); var files:Array = folder.getDirectoryListing(); var fileList:Array; [Code] .....
I am having an array of movieclips and when my circle(controlled with the keyboard) hitTests true with one of the movieclips inside that array i want to remove that movieclip from the array so when i hitTest it again it returns false (I hitTest using a "for in" with that array).How do i remove a specific item from within an array?
In my photo gallery, I have an array of images that load sequentially using 'next' / 'prev' buttons. The code fades out the current swf, recognises when the new external swf has fully loaded, then fades in:
I'm trying to create a class that contains an array. However i want to require that the items in the array are themselves of a specific class. Im told there is some sort of tag you can add to do this, but for the life of me i cannot find what it is.What i hope for is something like:
public class myClass{ public var foo:String; [ArrayType(class="BarClass")]
I'm using the following array to add children to the stage:
for(var i=0;i<6;i++) { var aCherry=new cCherry() aCherry.y=10 aCherry.x=10+100*i stage.addChild(aCherry) }
Now I want to modify each cherry based on another array. Something like this:
[Code]...
Clearly stage.getChildByName("aCherry")[i] isn't correct, but coming from JavaScript this makes the most sense to me and should accurately portray what I'm trying to achieve for you guys reading this. So, how would I actually do this? This being getting an array of children added to the stage under a certain name or class (so an array of cCherry would work too, if necessary), then using them in a way similar to the above loop.
I have an array Code: var myArray = new Array("James", "Doug", "Alex", "Katie"); Now, based on a text input I'll have, the user will type his/her name. Let's say thew value will be "Alex". How can the variable "Alex" returns me the number 3? I'm trying to make a movie clip jump to an specific frame based on what the user will type. Doable?
How could I get a number of all same objects in array (lets say I have five "Grass" objects and ten "Wood" objects. Now I want to get the number of Wood objects.
i have, i have a problem with my code.i have a mc (button) that when you click on it should go to a specific frame (the option clicked) and then charge a movie.the button (mc) ist created by a duplicatemoviehere is the code
I have 4 arrays named array1 to array4, is there any way to reference them dynamically? What I mean is if I have for example
var currentValue:int = 3;
and I want to be able to access a specific array depending on that value, is there an easy way to do that in AS3?In as2 you could do something along the lines of
I am using Flex to create a small form. All I have at the moment is a List component, that I want to populate with a list of font names.I am getting the fonts using Font.enumerateFonts(true);. This returns an array of flash.text.Font objects.
The Font objects have a fontName property that is a String of that fonts name.My problem is that I can't figure out how to bind the List's dataProvider to the fontName property of each of the Font objects in the Array.Is there a way to do this just with binding? and not creating a new array of Strings by looping through the Font objects?