Flash :: Interact With All Instances Of A Class From A Separate Class?
Jul 25, 2011
I've been hitting dead ends while programming lately all over, and I finally came to the realization all the code I have that is broken is because I don't know how to interact with instances of one class from within another. Here's the gist of what I am trying to do:
if(this.hitTestObject(targetClip)){
trace("hit!");
}
The problem is, if I address a single instance that is on the canvas, I get "access to undefined property targetClip", even though the document class can interact with it fine. If I target the class file of targetClip, I get "Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject". It isn't just a problem with hitTest either, I'm having this problem with other actions, so there is some basic syntax I'm failing to comprehend.
View 2 Replies
Similar Posts:
Feb 4, 2012
I've been searching around trying to work this out for a while now. There's been various ideas popping up, like dispatchEvent etc but nothing that seems to be a clear, simple way of doing this.What I'm trying to do is call a function from a class seperate (but in the same folder as) my document class.Specifically, I want to 'spawn' an object and run a function within that object's class from my Main.as.The snippet I have at the moment is as follows;
In Main.as:
var object:class_Object = new class_Object();
object.spawn();
[code].....
View 2 Replies
May 17, 2011
I'm new to Flash AS3. I started making a game and I am a bit confused. Let's assume that I want to create a game that has multiple levels/modes, how can I do this in an object orientated way?
When i create games in other languages e.g. XNA C#, i create a separate class then create an object of that class within the main class and run the game based on a simple statement.
[Code]...
View 2 Replies
Jul 8, 2007
I want to know how to make class instances into listeners and broadcasters, from inside each class. Here is what I am trying specifically... part of the Proj class... (projectiles, as a matter of fact)
Code:
private function listen():Void {
u.register(this);
onUpdate = function(){
step(); // a function I have which makes the projectile move (not shown)
}
}
where "u" is another class, the Updater class with this code...
Code:
class Updater {
// const. --- make this a broadcaster
public function Updater(){
[code]....
PS: What is the syntax for using AS2 code tags instead of just "[CODE|"?
View 2 Replies
Jul 16, 2009
I'm slightly new to Flash CS3 + AS3 combo, so its more of a lack of practice question. My question stems from the problem described here http:[url].... . Note, its not the same problem, its a new one.The Problem ,So I have multiple library assets (which are on teh stage) and I want to assign similar functionality to all of them.
Attempt 1: So I create the n assets, create a custom class in AS3, link them to Flash CS3 and obviously enough it gives me the error that multiple assets can't be linked to the same class.Obvious enough to understand (well not completely, because from a programmers background it doesn't make sense).
Attempt 2: Same as attempt 1, but instead of linking all the assets to the same class I make the base class the same class, and let the derived class be dynamically created by Flash on compile time.So the linking works, but the problem is, in my base class I have a method which does something (say an tween) on a child of the library asset. So if the assets on the stage/library are called asset1, asset2, asset3 (same name for asset name, class name, id name), each of them has a sub-movieclip called ... say 'foo'. now if I manually wrote a class for each asset, I could do 'this.foo' to play with the sub-movieclip. However since this functionality is in the parent class, I'm unable to do it.
P.S. If you're form a programming/OOP background, its basically a abstract class problem. My Base class knows how to doSomething(), but it needs aSomething, which is defined in the Derived classes. However I found out that AS3 classes don't support virtual(C++ )/abstract (Java) in the true sense of the word (unless I missed some obvious documentation).
View 3 Replies
Dec 23, 2006
Let's say i have a bunch of balls/cells. I'm having trouble figuring out how to make it so that every other ball bounces off of every other ball.
so in short, it's really one instance being able to check all other instances of the same ball class?
View 7 Replies
Sep 19, 2011
I am new to AS3 and I want to organize my code as what I did in C++, which I can have a .h and .cpp file. Is there any way to organize code like this in AS3? [code]....
View 2 Replies
Nov 23, 2011
I am making a little story thing which is sort of like a slideshow but I use sound in many parts of it. I searched online and the AS3 way of doing it seemed to be linking an imported sound clip to a class. My question is: Do I really have to make a separate class for each soundclip or is there an easier way of doing this if I plan to use these sounds multiple times? For reference, it should be roughly 434 sounds by the time I'm done
View 4 Replies
Mar 26, 2010
I have an xml gallery sort of that works fine when I have the code not as a class, in first frame in Flash. So I decided I wanted to port it into a class and the problem I get is at:
thumb = new Thumbnail(xmlList[i].image);
It expects 0 arguments. How come that line of code works in first frame in flash but not as a class? There is a movieclip in the library called thumb with linkage of Thumbnail.
Below if the code when used in first frame:
PHP Code:
var urlRequest:URLRequest = new URLRequest("pics.xml");
var urlLoader:URLLoader = new URLLoader();
var xml:XML;
var xmlList:XMLList;
urlLoader.load(urlRequest);
[Code] .....
View 4 Replies
Nov 20, 2010
I can access the targetObj instance inside the document class, but when I try to access it in another .as class,get this error:
Access of undefined property targetObj.
View 2 Replies
Dec 15, 2011
I have created a game in flash, and due to the nature of the game, I have many movieclips placed on the stage manually in Flash CS4. They are not programmatically added as children to the stage, and so I am having difficulty getting access to them in the document class. So far the only method I have been able to use is to do stage.addChild(active_area); (for example), but there are many movie clips, all very differently named, so this method seems incorrect.I've discovered that my MovieClips are not children of the stage, but in fact MainTimeline, as when I for loop through stage.getChildAt(i);, only one child, root1, is traced out. How can I access movieclips that were placed on the stage in the timeline from the document class, without having to manually add them as children to the stage? So it looks like my problem wasn't that I couldn't access the MovieClips, it was that I wasn't modifying the MovieClips' values, so I wasn't registering any change in them.
Here is the code after I fixed it:
function manage_cursor(e:Event):void {
prevX=currX;
[code].....
View 2 Replies
May 17, 2010
i have sprites in the library with linkages in them.. how would i create new instances of them if they are stored inside an array?
[Code]...
View 2 Replies
Dec 11, 2010
i have a function that looks as following:
private function createContent(slideData:Object):void
{
if (slide){
[Code]....
Now when i remove or add a slide I would like it to appear with a transition, I would like to create a separate class to put the different transitions in using tweenlite. How would I approach this the best way? So to sum up, when I add or remove a child, the transitions class gets called, it returns a transition and the slide gets animated when its added or removed.
View 2 Replies
Sep 2, 2010
Issue : Each swf which imports the same static class seem to have a seperate instance of that class.cenario: 2 seperate .swf's import the same static class. The Static class named Static has a setter function named test which has the default value of 'NO'. Swf A sets the value 'Yes' for the setter function and loads in swf B. Swf B then trace the value for the test method of the Static class but swf B traces the default value instead of the value set by swf a.
I would love to figure out a solution so I can keep using statics since I currently depend on them to do a wide variety of things in my current project.
[Code]...
View 0 Replies
Aug 2, 2010
The following is that long only because I gave examples of what I want to know, not because it is complex .I have three basic questions regarding AS 3.0 classes.
1. How can I make a class object interact with an object on stage?
For example, when I have a square (mc_Square) with class "square" attached to it and I want it to trace "Colliding!" and print the X and Y of the mc_Box on contact with an on-stage *hollow* box (mc_Box) that has no class attached to it.how to do it vice-versa would also be awesome .
2. How can I make a class object interact with the same class object? For example, when I have two squares (mc_Square) that both have the class "square" attached to it and when they collide, it prints the X and Y of both of them.
3. How can I make a class object interact with a different class object?
For example, when I have two squares mc_Square1 with class "square1 (that also has a variable Primary=true written in it)" and a mc_Square2 with class "square2"; When they collide, the one with Primary=true would be removed and it's X,Y position traced.
View 2 Replies
Apr 7, 2009
Is it possible to start and stop a sound file from a separate class? In the first class, "House", I have called the MP3 using the following:
[Code]....
View 1 Replies
Sep 30, 2010
When I try and access a function in a separate class, I suddenly lose access to all root access in that class.Heres some code.EnemyBase
ActionScript Code:
package
{
[code]....
View 9 Replies
Apr 7, 2009
Is it possible to start and stop a sound file from a separate class?In the first class, "House", I have called the MP3 using the following:
Code:
public var mySoundReq:URLRequest = new URLRequest("tune.mp3");
public var mySound:Sound = new Sound();
[code]......
View 1 Replies
Sep 13, 2003
if it was by any means (LocalCOnnect?) possible to create a footer that will 'talk' or interact with other instances of it on the same page... Now I know there is one problem because it's actually the same swf file
View 6 Replies
Jul 27, 2009
Should i keep Remoting Methods outside a class in a seperate AS file or is it possible to call Remoting inside a class.
View 1 Replies
May 4, 2010
When my document class attempts to instantiate a class in a separate package I get the error:1137: Incorrect number of arguments. Expected no more than 0.This is in reference to the following line:[code]As you can see, I have imported the package:[code]And here is the class that expects 0 arguments:[code]As you can see I properly labeled the Level1 class as part of the Levels package:[code]
View 4 Replies
Apr 16, 2011
you've shown me exactly what i need
View 6 Replies
Feb 24, 2010
Is it possible to refer to a variable in a class file separate from the one you are working in? Say Class1.as had a variable named "exampleVar", and in Class2.as you wanted to put something like "exampleVar++;". Is this possible and if so how would it be achieved?
View 1 Replies
Dec 31, 2011
I know it is possible to make instances/children interact with other objects by adding an eventListener to each child/instance.But how do you make a random instance/child interact with another random instance/child?Example: let a bunch of spaceships get damaged by a bulletrain by using addChild to place both spaceships and bullets on the stage.
View 2 Replies
Feb 17, 2009
Is it possible to create 2 instances of 1 class (for example: "Header"). Add these 2 instances to the stage on different positions. This Header class contains some buttons and what I want, is: when I rollOver one of these buttons, both buttons in the 2 Header instances are "rollingOver".
View 1 Replies
Oct 4, 2010
I have a piece of code, that moves an array depending on it's type. If the array is of TypeA objects, it will change TypeA. If it is TypeB it will change TypeB. The issue with the current code is the repeative blocks.
[Code]...
Which stops working whenever I need to access any property (user) selectedInstance.testSomething();
View 1 Replies
Sep 17, 2011
I need to get all the instances in my stage according to an especific class name. I'm doing this:
var class_ref:Class = getDefinitionByName('fran.MyOwnClass') as Class;
var element;
for (var i:uint = 0; i < this.parent.numChildren; i++)
{
[Code].....
But I want a better way (more efficiently, without checking all the MCs).
View 2 Replies
Oct 7, 2011
I made a .fla with some inline coding and some classes. In the .fla actionscript I have a function to read thru the object display list. Its the standard one found everywhere, where it recurses thru the objectdisplaycontainers. This works fine.
Then i gave the stage it own classname and moved the actionscript into a seperate .as file as well.
Suddenly, ik get this : Line 271 1046: Type was not found or was not a compile-time constant: DisplayObjectContainer. the code line is : function traceDisplayList(container:DisplayObjectContainer, indentString:String = ""):void
View 7 Replies
Aug 28, 2009
bit of an odd problem, I have the following piece of code
Code:
var myCookie:SharedObject = SharedObject.getLocal("mySavedData","/")
if(myCookie.data.mySavedText != undefined)
{
var gallerypath:String = myCookie.data.mySavedText;
}
which retrieves a shared data.
If I put this actionscript on the first frame of a new document, it works fine, however I want to use it in something I already have, which uses an external Document class.
[Code]...
View 1 Replies
Oct 8, 2009
I recently learned how to use gravity so I made a bouncing balls program but I have an issue with the interaction between the frame timeline code and the class.The problem is that when I create instances with a timer, I declare the variable inside the timer function. And I want to add a blackhole sort of thing when I click down on the stage but I cannot access the object from the blackhole function since it's declared inside the timer.
View 4 Replies