ActionScript 3.0 :: Have Two Objects Of Same Class Detect Each Other
Sep 21, 2010
I have a map and I have some objects that I place on the map symbol. I am NOT dynamically creating them.
Lets say there is 3 objects all linked to the CollisionDetect class. The player can move these objects around fine, no problem but I want to make it so the player cannot push the objects on top of each other.
how I can detect that Ob1 of the class is hitting Ob2?
Internally Flash obviously keeps a list of the primitives drawn using Graphics so I wondered if you have many such primitives in a Sprite, can you re-position/remove/alter individual items rather than clear and re-draw everything? Or is this deeper into the bowels of Flash than you're allowed (or recommended) to go?
What I have is a game with a Level object, inside the Level is a Player object, and they don't have instance names given, what I'm trying to figure out is how to do is make it so that the player can change the x or y properties of the Level object.
To be more precise, I'm making it so that when the player moves in a certain direction, he either moves accross the stage, or he starts moving the Level object around the stage, it'd be in an Event kind of function, now I can easily make the Player move, but I don't know how to make the Level object move which the player is inside of.
I'm working on a game right now where I'm going to have paths dynamically built by the user for multiple AI objects to "walk" along. I'll be detecting/redrawing the path only on user input but I'm still debating over the fastest possible method to update the movement of many AI objects "walking" along/up/down the given path. Think for example of pac man, but the level is dynamic. Right now I'm leaning toward building the enemies in a linked list of final classes and looping through the linked list calling a function in each of the AI objects to plot the next move along the path.
Is there any way for a Flash component to look up the URL of the website it is embedded in? For example, if I embed a YouTube video on my website, does Google have any way of knowing who referred to them?
I've written a bit of code that will allow users to move objects around the stage and detect if one has hit another. The problem is that it only works for a limited number of objects. how to rewrite the code so that it works with an unlimited number of objects?
Is there any way for a Flash component to look up the URL of the website it is embedded in? For example, if I embed a YouTube video on my website, does Google have any way of knowing who referred to them?
I have question regarding removing instantiated objects. Let's say i have a main class in which i instantiate a custom video player (or whatever) class:
Code: ... var videoPlayer = new VideoPlayer(...); addChild(videoPlayer); ...
And inside VideoPlayer class i have of course dozens of objects (movie clips, sprites representing different parts of VideoPlayer) and dozens of event listeners attached to them. My question is, if i want to remove this VideoPlayer class from my main class is it enough to just do:
I have a class that represents a turret in the center of my screen.When I hold down SPACE, I want it to create a "bullet"-object that moves in the direction of the turrets cannon, every frame the SPACE key is held down. I am having problems with this cause I am getting this error when I am trying to create the object:
Error #1009: Cannot access a property or method of a null object reference.
This is where the error occurs:
ActionScript Code: public function chaingun(x_:int, y_:int, rot:int, cd:Number, spd:Number, sprd:Number, life:Number) { this.Cooldown = cd; this.Speed = spd;
[code]....
PS: What happens is that when I press the SPACE key, the "turret" class event handler runs the function "Shoot_Chaingun" and that function creates a new Chaingun-object (which actually is a bullet), that inherits the x, y, and rotation of the turret, along with some additional varaibles, including lifetime. Then upon creation, I use "addChild(this)" to add it to the main stage, and "removeChild(this)" once it's lifetime is up.
EDIT: And also, I just realized I don't have a MovieClip linked to this chaingun class. How do I make sure that every time a chaingun object is made, the MovieClip is also loaded?
I have an enemy on the stage that reads whether it's being hit by a bullet by a hittest. There's a for loop inside the enemy's class that looks for all the bullets and names the bullet that's hitting it "hitBullet". What I'd like to do have an easy way of seeing what type of bullet is hitting the enemy. I'm basically looking for something like
if (hitBullet == RegBullet) { //do regular bullet dying }else if (hitBullet == ClusterBullet) { //do clusterbullet dying }
, where RegBullet and ClusterBullet are classes. But I have no idea what hitBullet is equal to when a ClusterBullet or RegBullet hits it. I traced hitBullet to see what it would return and got "[object ClusterBullet]", but I'm not sure what that would be in the actual code.
im trying to detect when the my mouse crosses an object within my "game".
my object has its own class and is created on the main file in a loop (when you press space)
i want it to listen to MOUSE_OVER event but when i add the eventListener to the object it doesnt detect it.
the only way i found to get this event to happen is to create my own event and on every frame check if the mouse pointer is inside the object, and dispatch the costume event. the problem with this method is that it wont detect the mouse if it passes over the object fast.
by the way im using Box2d engine
Main Code: var launchPoint:Point = new Point(G.randomNumber(100, 500), 420); var direction:Point = new Point(G.randomNumber(200, 400) , 10).subtract(launchPoint);
I am trying to create a simple drag and drop Flash program where a user can drag xmas ornaments onto a tree. Instead of being able to drag the ornament once, I want a function so that every time an ornament is clicked on, it adds a new ornament of the same class to the stage where the ornament is clicked. Currently I have this working but there is one problem. It is not dynamic. Looking in the "drag" function, I have chosen the class "Symbol31" as the default ornament that gets added. Instead, I want the ActionScript to read the class of the ornament that was clicked on and to add that class, not "Symbol31" everytime.
Code: public class DragDrop extends MovieClip { private var originalX:Number;
From my main flex mxml, I am trying to detect the size of a rect:Rectangle that I created in my InfoBubble.as class. The info bubble itself is created in my InfoMap.as class. How can I access the attributes of the rectangle I created?
Here is the variable portion of the InfoBubble class:
Code: public class InfoBubble extends Sprite { //public var textField:TextField;
I'm building a video chat in flash and everything works really well, except for the part where I'm trying to detect if the other user is sending a working video stream. There's a couple of reasons why the other user isn't sending video. -The other user got no camera -The other user got a camera, but the camera is currently being occupied by another application(Skype, Photo Booth, Google Talk, etc.) -The other user got a camera but hasn't allowed the use of his/hers camera. (Other unexpected problems I guess...)
So how do I detect if the stream I receive from the other user is a black stream(because of the reasons above) using the NetStream class? The closest thing I have came up with is by adding a timer that polls the currentFps() function from the stream I receive from the other user. But so far this seems pretty unreliable because I might get currentFps() == 0 and show an error because of this even though I actually got video from the stream in some cases. The reason for this is because I poll the API every 4 seconds for the currentFPS function and let's say at 00:00:04 I get "no video" according to the poll but at 00:00:05 the video kicks in, and therefor I need to wait until the next tick until the error message disappears
This is what my current poll looks like function subscribingStatusPoll(e:TimerEvent):void { if (subscribingStream.currentFPS == 0){ error.text = "No video found from the other user... } else { error.text = ""; }}
This is the only hack I that I can come up with to detect this, but this is unreliable and I actually would prefer a way to instantly detect if the stream I receive got a working video attached to it.
I am working on a small section of my game and am attempting to detect key presses from an external class but I cannot get it to work. This code worked just fine when within the document class but now it's unresponsive. I'm not getting any errors, simply no activity whatsoever.[code]...
I'm working on an Adobe Air application written in Flex 4 that plays .mp3 audio files on the user's computer. Note: these are are not audio files shipped with the application -- they are .mp3's on the user's computer that they select for playback through the application. The application works fine for .mp3s encoded at 44.1 kHz, but can give unpredictable results if other sample rates are used. I've done plenty of research to know the limitations of the Sound class and how .mp3 will basically be my only option in Flex.
My question is: Is there a way to detect the sample rate of the .mp3 audio in Flex 4 ActionScript? Rather than worry about making the application work well with non-standard sample rates, at this point I'd like to just catch those cases and prevent files with non-44.1 kHz sample rates from loading. To be specific: if a user selects an .mp3 for playback that has been encoded at 48 kHz, for example, I'd like to be able to detect that case and take action preventing the file from loading and then announce to the user that this is not a supported audio file.
I have some data (preferably objects, insteads of string) in the flash which I want to store as table format. So that I can query them. It is not datagrid as I do not have to show them. Currently, I am use "xml class" because of the query function. However, "xml class" cannot store objects.
I created multiple classes for a platforming game in AS3 and when i am making the levels i simply drag the objects of a certain class to the stage from the library. My problem is that i am unable loop through all of the objects of class type wall from another class of players.(so that i can make every player created not go through every wall created)
Like: for(i=0 i<numberofwalls i++){ do sumthing with wallobject(i) }
Are there any functions that can return the number of walls dragged to the screen and one that lets me access each individual wall dragged to the screen?
I have two objects, both brown squares. I want them to be members of the same class but one square to have a number "1" in the center and the other to have a number "2" in the center. Any ideas on how I might accomplish this? Any clues on how to instantiate a vector drawing (drawn in illustrator) from ActionScript 3 as opposed to dragging it on stage from the library in flash?
im currently writing a piece of code where i need to get all children that are specific class or extend one.
currently im using this
ActionScript Code: public function getConnections():Vector.<NodeConnection>{ var res:Vector.<NodeConnection> = new Vector.<NodeConnection>();
[Code].....
The problem with this is that 1st, string comparison is slow, and im expecting that there will be hundreds, of instances on stage. and secondly, It is very probable that i will extend the classes that i use in the functions, so their toString() will produce different name. e.g if i have on stage instances of "Node, ExtendedNode1, ExtendedNode2 " since they are all nodes, id like to all of them be returned.
Probably a very easy question, but Google and Livedocs are both failing me here. I have a custom class (Which I shall refer to as "Circle"), and simply wish to find each of the "Circle" class, and add them to an array in my Document class. I may also need to perform this task from within other classes.
I've considered having each 'Circle' on creation send a sort of "signal" to the document class for it to add it to an array or vector, but can't figure out how to influence the Events of its Parent class.
We'll call it "song" for the sake of example...song has the attributes artist, title, album. upon makign all the objects, i put them in an array.[code]...
whether i want to find one object that has a unique attribute (like "london bridge", maybe) or multiple objects that might have the same attribute (like an artist or album), is there a more efficient way?
How to access stage elements from within a class. buttonControls.as
Code: package { import flash.display.Sprite; public class buttonControls extends Sprite { // Navigation Hover Color var hover = "0xF1E960"; var normal = "0xFFFFFF"; public function changeColor(object, color){ [Code] .....
I'm trying to access a MovieClip created within the authoring tool from an ActionScript class. Here is my code:
PHP Code:
package { import flash.display.*; public class MoreVideos extends Sprite {
[Code].....
I also tried changing that to [stage.moreVideosBox.visible = false;], but I then got "1119: Access of possibly undefined property moreVideosBox through a reference with static type flash.display:Stage."
Is it possible to directly alter items in the authoring tool from a class? If I move 'moreVideosBox.visible = false;' outside of the class, in the main .as file, it works fine.
When I try to do this in an AS CDATA block, it tells me I can't have a class declared within a class (the MX:Application itself). Makes sense. But where and how do I do it?
Let's say that I've a button object (instance of Flip) and a coin object (instance of Coin) on the stage. The coin object has two frames: one showing Heads and one for Tails.
MyCoin class is as following:
package { import flash.display.MovieClip; public class Coin extends MovieClip
[Code]....
Problem: How do I reach the coin object on the screen via onMouseClick function? Let's say that the object on the stage has instance name of myCoin. I suppose that had I not done this with an external class and simply used actions from the frame I could just use the instance name as a variable. I couldn't figure to do the same it in an external class. Do I first create the object which is already on the stage?