ActionScript 2.0 :: Arrays In A Class Instance?
Aug 3, 2010
Today I found a thing that really bugs me. Let's say I have this very basic class called Test which basically just creates an array and stores some objects in it:
Code:
class Test {
private var _arr:Array = [];
function Test() {}
[code]....
Code is the very same, I am not copying it here cos it has no sense to do so.
View 3 Replies
Similar Posts:
Jan 22, 2010
I have a base class which is being created via remote_object [RemoteClass alias] from the server.I have other specialized classes that are derived from this baseclass, but serialization with the server always happens with the base class.The base class has meta data that defines what the derived class is, for example
[RemoteClass (alias="com.myco...')]
public Class Base
{
[code]....
View 2 Replies
Sep 15, 2011
I'm using a library that has a function that returns an instance of some class Engine.
I'd like to tack on some interfaces to Engine, so I subclass it class InterfacedEngine extends Engine implements AwesomeInterface. but when I change the code that uses the classes from this:
var engine:Engine = generateEngine();
to this: var interfacedEngine:InterfacedEngine = generateEngine();
It gives me a runtime error (elision mine):
TypeError: Error #1034: Type Coercion failed: cannot convert ...::Engine@1bc2bf11 to ....InterfacedEngine.
What about AS3 classes am I misunderstanding?
View 2 Replies
Oct 14, 2009
I have to admit I pretty much ran away from Flash when AS2 came along and only used it for animation purposes over the last 5 years.So I'm having a major crash course in AS3 in Flash CS3 and I'm not enjoying it one bit. I'm getting maybe 10mins of finished work per hour as I try to figure out the limits and rules of AS3. Quite often it seems that AS3 simply can't do what I want it to. Anyway: Characterchecks.as is the main class and it loads a bunch of XML into four arrays. The file starts like this:[code]If I trace the value of, say, cc._Categories from the main FLA, it's empty. I'm guessing that the next line of AS in the main FLA doesn't wait for the previously called function to complete? (This may tie in to my next problem)My next step is that I want to display various things based on the data in the array. I have another class, Display.as which will hold all the functions to create the items on display. I thought it would be best for these to be a separate object. I wonder if I'm right?
So I declare an instance of Characterchecks in the main FLA and call it cc, and then run the functions to populate the arrays... Now I create an instance of Display and call it cd. How can I get functions in cd to see the values of the variables in cc? And if the main timeline can't tell that the functions aren't finished filling the arrays, how is cd supposed to know?I might be asking dumb questions, or maybe I'm doing things ***-backwards, I don't know. I'd appreciate any help, I really would. This whole thing has me at the end of my tether... being the most technically advanced person in my circle of co-workers and web design friends means I have no-one to explain why things need to be done a certain way or what the best way is.
View 3 Replies
Apr 14, 2011
I'm creating a little game - The player controls a character that follows the mouse. Pigs run away from the player, and the player has to get them all into a pen. To make the game a little more difficult I'm trying to add an enemy - wolves, that attempt to perform a 'hunt' method every x seconds. This method sends a reference of the wolf instance to Main (my document class) and Main then loops through the pigs on stage to see if there's any nearby. Now as far as I know this works - my problem is I'm unsure how to send the pig instance reference back to the wolf that called the hunt method, so it can then 'target' the pig, and then attempt to pounce on it.
This is my Wolf class:
Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
[Code].....
View 7 Replies
Dec 10, 2010
Quick question. I have been Googling this all morning, but it's either not there, or else written in a way that doesn't register. I am inclined to believe the latter, as this seems like it should be something completely trivial to me. I made a small Flash file using AS 3.0, and this is the first time I've really been able to stick to the OOP way of doing things and not hack together a mix of stuff from the timeline to get around not having everything work in the classes.
So I'd like to keep it that way, but one thing is eluding me: I can't call a method of an instance of another class (than the one I'm calling from) without resorting to "DocumentClass(root).instanceName.method." Intuition tells me there has to be a better way of doing this (like, without having to reference the document class every time I call another class instance's function; and CERTAINLY without having to use the word "root" - that just seems so Flash 5 to me. Does anybody have a better way of doing this that they can share?
[Code]....
View 1 Replies
Apr 14, 2010
I'm new to Actionscript 3.0 and flash and I'm trying to make a simple drag and drop project that using externalinterfacecall will have javascript check or uncheck a value on a webpage when an image is dropped into a certain box. I'm trying to give myself a solid string to pass through to the javascript however when I do this one way, I get a stack overflow that is as follows :
Actionscript Code:[code]........
View 3 Replies
Jun 16, 2011
I'm trying to turn an string into an instance name.
stage.focus = ["box_"+[i+1]];
this gives me back = box_2;
but I need it to be an object not a string.
In as2 I could use eval. How do I do it in as3?
View 3 Replies
May 17, 2009
- I tried, when I first started making this site, to load all of the artwork images into an array and then copy the array before resizing them for their specific functions (being seen as thumbnails or as full size pics.) Unfortunately, I ran into the well known issue of Array cloning only creating a pointer to the same group of items. I tried the newArray = oldArray.slice() trick, but it didn't seem to work. Finally, I just loaded the images twice into two separate arrays, and it works, but I hate this solution. Anyone got a better one?
- I'm trying to maintain some sort of connection between the two sets of Arrays so that, for example, when someone clicks on Thumbnail 15, Fullsize Image 15 will open up but I couldn't find anything that worked. Renaming the Instance Name dynamically didn't seem to work and adding an Instance Variable dynamically doesn't seem possible either as I can't make the Class I am working with (Sprite, in this case) dynamic ahead of time. I'm sure there's a simple method for this.opens up, the different animations seem to interfere with each other and slow each other down (they also seem to get interference from the time taken to load the image Arrays.)
View 9 Replies
Jan 26, 2009
I have a general / somewhat newbie question. Is it better practice to call a function from another class like so:
[Code]...
Does one way free up more memory or enhance performance?
View 5 Replies
Mar 8, 2012
I am trying to test the collisions between a bullet and an array of enemies in Actionscript 2. However it is not sensing a collision.This is the code in the bullet.
onClipEvent(load)
{
facing = _root.player.facing;
speed = 1;
[code]....
View 1 Replies
Feb 17, 2011
Is there a way to generate an instance of a class that implements an interface based on the name of the class?
I am trying:
var ClassReference:Object = getDefinitionByName("movement.OuterSpaceMovement") as IMovement;
var m:IMovement = new ClassReference as IMovement;
trace("startup..." + m);
-But I am getting an error message ReferenceError: Error #1065 (OuterSpaceMovement) not defined.
I have several classes that implement the same interface (IMovement) but I need to be able to generate new instances of these classes and then pass these instances as a datatype (IMovement datatype) to other classes...
So then I tried:
var ClassReference:Class = getDefinitionByName("OuterSpaceMovement") as Class;
var m:IMovement = new ClassReference() as IMovement;
and this doesn't seem to work...but the following
var m:IMovement = new OuterSpaceMovement();
View 1 Replies
Jul 22, 2009
I'm trying to create a new instance of a MovieClip when the original one has been used. Would sound easy enough. Just use: var
instanceName:ClassName = new ClassName();
the class name/mc in the library im trying to duplicate is MCg1 so
var instanceName:MCg1 = new MCg1(); right?
However, the particular object in the library i'm trying to duplicate has a base class that is an external class file (just to control it's drag drop functionality)... i.e baseclass is not set to the standard flash.display.MovieClip, or whatever the case maybe. So i end out with a: TypeError: Error #1009: Cannot access a property or method of a null object reference.
View 6 Replies
May 11, 2006
I've done a class to be able to listen to the event for a CLASS not on an instance.
Code:
class net.webbymx.events.XClassEventListener {[code]....
why did I do this.It cames with my rugby game.I have player in two teams. When a player throw the ball I want the other teammate to act like "wait for ball" and the opponent like "seek for ball". Plus I'm lazy (and I don't want to register the listener for each instance of the player I'm creating). So this class is made to be able to handle as many instance of a class I want without adding a listener on each of them. I'm just creating a global listener on the class and then I will be able to receive dispatched event for any instance of this class .so in my team I can do
Code:
XClassListener.initialize(this);
this.addEventListener("throw", "net.webbymx.game.Player", "wait");
and in my opponent team I can do
Code:
XClassListener.initialize(this);
this.addEventListener("throw", "net.webbymx.game.Player", "seek");
View 4 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
Aug 31, 2011
When I declare a class variable
private var myVar:MyClass = new MyClass();
It creates a new instance of that class that will trace as [Object MyClass].
However, as soon as I assign it to something
myVar = thisOtherVar;
It will now trace as [Object thisOtherVar].
I need to get it back to where it's just an "empty" blank class instance, if that makes any sense at all.
View 14 Replies
Jun 28, 2010
Given that both of these calls to getQualifiedClassName return the same thing (mx:Label), how would one go about programatically differentiating between an instance of a class and a reference to the class...
var lab1:Label=new Label();
var lab2:Class=Label;
var qcn1:String=getQualifiedClassName(lab1);
var qcn2:String=getQualifiedClassName(lab2);
In other words, how could I know that lab1 is of type Label, while lab2 is type "Class". typeof() simply returns "object" for both... getQualifiedClassName returns "mx.controls::Label" for both...
View 3 Replies
Dec 28, 2005
I have a class called Unit. When I use this class in a .fla file, I create it by saying:
var unit00:Unit = new Unit(...);
So then it creates a gfx representation of the screen for me. I would like to have a method like this:
PHP Code:
[code]....
So how do I get this to work? I know that delete this will not work when defined inside the class. How do I target the .fla's instance name when I don't know what it will be called?
View 10 Replies
Apr 6, 2010
I mean a have a class called Login and when I make an instance of this class
PHP Code: var log:Login = new Login();
doesn't give me the wanted results.
- When it is declared Document class it adds a child on stage
- When the same class is called manually (via the above code) although I get no errors nothing is added on stage.
View 3 Replies
Mar 31, 2011
I'm having a problem where I can't make an instance of a class in one class like I can in other classes all in the same package. When I call the update function from another class it doesn't work. I traced the xPos of the instance of the class I was talking about and I get zero, but that is incorrect so I'm thinking it's the above problem. If anyone knows what the problem is please tell. Here's my code:
[Code]...
View 1 Replies
Oct 7, 2010
I'm creating a Papervision3D scene in a document class. I have added an instance of a PointLight3D object. I'd like to create a class that uses the light instance in the main document class for its material. What would the Actionscript be to do this? I can't refer to the light as super.light because my class is inheriting the Sphere class. parent.light does not work either (even if I wait for the class to be added to the stage).
View 2 Replies
Mar 15, 2006
I want to retrieve the var reference of an instance of a class from within the class. For example:
ActionScript Code:
var ref:MyClass = new MyClass ();
//then via some method, I would like to get the var ref inside the class
ref.getRef(); //returns "ref" instead of [object Object]
[Code]....
You may ask why, well I want to do some spring cleaning inside this manager class I am making. Of course the above is a simplistic version of what I am trying to do.
View 2 Replies
Jan 7, 2005
how can I self refer to an instance of a class within the class definition file?Here is an example
PHP Code:
public function fireBullet(target:MovieClip) {
Bullet_mc = target.attachMovie("Bullet", "Bullet1", 1);
}
}
Now everytime I want to call the function I have to put this as my target, (fireBullet(this))I cannot just put it in the code as it gives me an error.
View 9 Replies
Apr 15, 2012
I got a ton of movieclips in a class. Is there a more efficient way to apply a function to every instance in the class other than this?
var textArray:Array = [
interludes.interludeIntro.interludeBegin1,
interludes.interludeIntro.interludeBegin2,
[Code]....
I have NO idea why the above doesn't work. I want to turn every single instance in the class interludeIntro invisible, but I want to turn specific instances visible later.
how to insert code on this website, pressing "code" doesn't do anything, so pardon the bad formatting)
View 2 Replies
Aug 17, 2011
I was wondering if it was possible to create an array of classes in Flash. Is it possible to do like in C++ where you can do the following?
CDog dog[100];
for ( int i = 0; i < 100; i++ ) {
dog[i] = new Dog();
[code].....
View 1 Replies
Feb 3, 2009
I have a private class variable that is an array. I have the getters and setters like I would for any other variable. When I push something on to the array from outside of the class using the instancename.arrayname.push() it pushes it onto all of the arrays of all instances of that object like it is a static variable or something.
View 2 Replies
Oct 29, 2009
Anyone familiar with tiles,multidimentional arrays and class file? I am doing a tile based game; buttons with Lots of multidimentional arrays and using .as as the class and import them to my .fla file.
the tile map is finished. like you can see in the picture. This is my code for the Tiles.as file;
[Code]...
View 8 Replies
May 10, 2011
I did a separate levelData class to be able to flexibly add levels. I was happy with it until my supervisor ordered me to convert my levelData into XML. I did an XML version of the levelData's data (question, answers, correct answer...). I used the old class and converted it so that it fetches the XML.
All seems well, I did traces of my answers array and it printed nicely...
But the headache started when I tried this.
// This code appears in a different class with
// currentLvl:LevelData initialized in the constructor.
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
[Code].....
LevelData Class in PasteBin: [URL]
View 2 Replies
Oct 11, 2011
I try pass my Arry to Class. I try to pass it and it look like this: Frame 32 earlier are some animations.
[Code]...
View 4 Replies
Jan 9, 2010
I have a function that takes as parameters 2 instances of a (custom) class. But they can each be one of several classes, and I need to then call another function based on what type they are. I'd like to do something like this:
function any_any(inst1, inst2) {
this[inst1.classname + "_" + inst2.classname] (inst1, inst2);
}
[Code]....
Should I go and define 'classname' in each of my classes, or is there a better way to get the class name of an instance? I don't know how to get typeof() to return anything other than 'object' for a custom class, maybe it's possible?
EDIT: It would be inconvenient to use the instanceof operator, as each class can be 1 of 6 (currently).
View 3 Replies