ActionScript 3.0 :: Change Variables From Class In A Deffirent Class?
Oct 16, 2009
Now I would like to use the variable out of class1 in class2 and change the value there.Afterwords use class2 in the main, but I get an error message. Why?
I have a initApp.as which instantiates a class which needs to access the "currentState" property and the States array as well. However we cannot get this to work as we cannot see how we can access this information.
Within initApp.as currentState is accessed via "this.currentState". This does not work in the class which is instatiated within initApp.as. The following error is thrown:
I am creating a Weapon class for a game and the weapons itself will be the sub classes. The sub classes will hard code some values (such as max ammo and the weapon name).
I trying to access this declared data in the base class constructor, at the moment it's not outputting the values. Is this possible?
My current workaround is creating a protected method in the base class to trace the information and calling that method in the sub class's constructor, this works fine but this doesn't seem like the most efficient technique?
What is the correct syntax to initiate a function in a class similar to constructing an associative array? I have a function that's custom variables is ballooning out and I'd like to label them in the call for sanity sake.
How do I listen from the main class to a sub class for a variable change?
package { import flash.events.* public class DataBase extends MovieClip {
[Code].....
This is what I have so far for the sub class but I can't seem to figure out how to listen to this variable change from Main() or even if I am dispatching the event properly.
I have two classes, class A and class B, where class A contains an input fields and its value can be modified by calling its instance name and giving it a new value
I get the trace statement message but it doesn't change the value of myText_txt fields.I tried extending class A in class B but I got an error that says TypeError: Error #1009: Cannot access a property or method of a null object reference. Thats why Im using the composition method but as you can see it is not working.
I have a child class that is loaded into the parent class when the swf begins, like so: var myvar = 'hello'; public function Parent() { this.child = new Child(); }; How can I retrieve the variable 'myvar' from within child?
I'm having some problems importing a class, the message that Flash gives me is this; The class being compiled, 'ImageLoader', does not match the class that was imported, '[URL]'. The only line of code in my flash movie is this: import com.martijndevisser.*; And yes, the class is in that folder The class is from here: [URL] I've used the class before and it works fine, I just dont know what to do?
Is it "better" to initialize AS3 class variables in the class constructor? Or can I just initialize them to their default value when I declare them at the top of my class? I ask because when there's a lot of class variables, it appears inefficient to declare them in one place and then initialize them in another when I could easily do both in the same place. It one option is better than the other,
I was wondering how do you name variable in your class? I mean like i give function params and variables names like these:[code]Where the "i" would show the type and so on. So how do you name your variables to make it easier for you to work with them?
how to reference a variable that is on my main timeline into a class.Or I need to know how to pick up a variable from my php file (as in "myswf.swf?variable=3") into my class.This was all very easy to do in AS2.I just can't find out how to do it in AS3.
First off I don't understand classes, how to "call" or "initiate" them. I'm class ignorant.
I have two .fla files. One of my .fla files consist of 15+ .as files; we'll call this one XML editor. The other .fla file consists of 10+ .as files; we'll call it the interface.
The xmleditor.swf loads the interface.swf. Within the xmleditor.swf, a login screen appears and the enduser logs in as either a "user" or an "admin". The "user" or "admin" is stored in a public variable called "userType". The userType variable is created in one of the many xmleditor.fla .as files called Login.as.
Once logged in, xmleditor loads the interface.swf. interface.fla uses 10+ .as files. one is called nodeNames.as I need an if statement in nodeNames.as that is something like this:
if (Login.userType == "user"){ trace("do something"); }
I have the following FlashVars.as file but I have no idea what the steps are to make it work.
I have a bunch of variables in a class. There are situations when I want to set then to null/ "temp" etc as per a well defined logic. The challenge is to list out the variables at multiple places- tedious and error-prone.
would prefer a way to refer to these variables programatically and set something like "for all class variables- if variable ends in type, set as "not_set"; for other variables set as NaN How can I achieve this?
I'm trying to create an XML class to load some images on a stage, but my problem is that I can't access variables in my XML class(which I need to load the images) from the main timeline after I've created a new instance on the XML class.[code]...
I want to create a "release" method for my classes which will basically remove all event listeners and null any properties so that the garbage collector can do it's job. I would like to put this method in the base class which other classes will extend so that I don't need to manually write this method for each class.
Is it possible to run a for loop through all the properties of a class so I can null them without knowing what they are?
I've tried "flash.utils.describeType (this)" which will only give me public variables in the returned XML.
I am just writing this test code in AS1.0. Now the problem, I am not able to get access to my class variables. I am doing this stuff for learning As1.0. Although in 2.0 I get through those using static variable. But in As1.0 I don't know how to do this.
I was wondering if they found a better way of allowing the use of variables outside of an on function. For example in the script below I can use the variable bounds inside the target.onEnterFrame function because it's declared inside the constructor. However I can't use m_Bounds even though it's declared in the class.[code]...
i have created a Vehicle.as file and a Car.as file which are in the same project. The problem i am having is trying to use the properties in my Car.as from my Vehicle.as file.Vehicle.as
I add the sprite to the stage and define it's x and y in the class file. How would I go about changing the x and y of the container within my fla file?
In AS3 I want to use Global variables (not many) that can be accessed in any class and declared somewhere where the fla file or any as file can use them and be ale to change the value of them anywhere. Can I do this in AS3?
I have created a loader class that retrieves variables from an external text file. I call the loader class and all works well but I cannot figure out how to retrieve and use the variables in the Main class.
I have a class Grid which produces a graph paper like grid on in the drawing area. I then have 5 other classes for different shapes to draw with; Line, Polygon, Ellipse, Curve, Arc Now, these 5 classes use an instance of Grid because Grid has a resolution and a scale. Inside Grid I have:
public function set resolution(x:Number):void { _gap = (modBy10(x) / 10); _scale = (modBy10(x) / (this.resolution * _scale));
[code]....
I'm just lost for a solution on how to update every instance of my 5 drawing classes when Grid is changed.For instance, Polygon is made up of multiple instances of Line, Line(length, angle) where "length" is in either in, ft, cm, or m. If the user wishes to change the scale from say 10ft per 100px resolution to 20ft per 80px.. Is there an easier way than re-drawing every Line inside Polygon?
I have a project that works quite beautifully right now. I have come to my next task. Creating swfs that are loaded into another swf. This newly loaded swf needs to grab some variables from the main swf's document class or global variables class that I have created. I have set the class path as such that it can access the classes as needed. I did not set a document class.
I'm pretty new to working wth custom classes, but so far everything has been working great - up to the point where I create more than one instance of the same kind of class. For example:
[CODE]...
Do I simply have to call the arrays different names??? I really don't want to, shouldn't by creating two different instances you subsequently create two different arrays in turn?
when I have access to my variables. I have the the follow code:
class Slider { var myVar = 4; function Slider () {[code]....
The slider function is being called first to update the myVar value then the findValue function is called. How do I get the find Value function to output 6 ? I want a function that updates the main classes' variable so thet I can use it from any function.
this works, but what If I want to change a variable declared in the button?
I would like to retrieve from an XML the movie I want to load pressing this particular button, but seems like the scope of the "designed" objects and the programmed object is a little different, since with
[Code]....
I've included a simplified version of the interface, the classes and the code is not 100% functional...