ActionScript 3.0 :: Accessing The Private Variables Of One Instance Of A Class?
Aug 18, 2010
Currently I have two classes which are "bullet" and "enemy".There are two instances of the enemy class.Code from an ENTER_FRAME event in the Bullet Class:
ActionScript Code:
try
{
for(var k:int=0; k<getEnemys.length; k++)
[code]....
The Enemy Class has a private variable called "hits".What do I have to do in order to reduce the hits of the instance of the enemy that was hit by the bullet?
View 5 Replies
Similar Posts:
Apr 9, 2011
I have a class that creates an array from a config xml file. I set a private variable in that class and use a getter in other classes to access the array. The routine that uses the array does the following:
- Call the getter and assign the returned value to a local (private) variable tmpArray. the getter is a simple return() using a value that is established in the constructor.
- Uses a for loop to itterate over the contents
- Uses array.shift() to pop the item in tmpArray
The next time I run the routine, the contents of the array is empty. I'm using the same getter. I implemented the getter when I tried to manage both arrays in the same class figuring that as long as the original array was private (i also tried static), that the value would not change. I have since worked around the problem by moving the routine that fills up the original value from the constructor to the getter. So, consider the following code:
import flash.events.Event;
btn.addEventListener("click", btnHandler);
var myArray = new Array();
var myTmpArray = new Array()
myArray = ["one", "two", "three"];
myTmpArray = myArray;
function btnHandler(evt:Event) {
[Code] .....
If I create a variable myVar and set it to 1 then set myOtherVar = myVar, the both equal the same value. If I change the value of myOtherVar, myVar is not affected. But using the shift() method changes both the original and the copied array.
View 5 Replies
Jun 2, 2011
Here's my main class:
[code]...
in the timeline I have a dynamic text box named my_textbox: var my_test:main = new main(); my_test.check_DVBViewer(); my_textbox.text = ??Basically the class waits for the callback variable (my_msg). The problem is: I need to set the dynamic textbox text to my_msg variable. How can I access it? I know I can access a public var in the timeline with functioname.variable but I can't define a public var inside a function, right?
View 3 Replies
Oct 13, 2009
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
Code:
package
{
[code]......
View 14 Replies
May 25, 2011
there are classes definitions where all their methods are private my question is why are they private, because i've tried a code wherein i changed all the private access modifier to public and nothing changed!
what if you make an instance of that class with all its method private, how are you be able to access that on another class. coz i know private methods are only accessible to the class where they are declared! will the instance of that class be able to access the superclass's private methods!
on private variables, it's still not clear to me as to why make a private variable and then use a getter and setter, when you can simply make it public! are these variables called static?cause on the way i understand it private functions and private variables are static?
View 1 Replies
Nov 26, 2006
Okay so you've got your private vars in your AS2 Class, you think they're all safe right? Wrong.
Doing a trace(MyClass.myvar); will spit out an error that the var is private and you can't touch it.
But a trace(MyClass["myvar"]); will work perfectly fine. You can use it normal, without any setters getters outside the class.
Is there a way to protect against this? I think this is a huge security flaw. I know it's simple OOP, but a private var in an object should have rules.
View 7 Replies
Jun 5, 2009
I have a really peculiar problem that relates to the old question of how to best access the instance of the document class from a different class. I usually add a 'this' as parameter when I create an instance of another class inside the document class. Then I save this 'this' in a class property of the type 'Object'. It usually works just fine but lately I have encountered a really bizzarr error.
When my movie first starts I have to load 2 xml-Files. I do that in another class - that calls upon the document class instance when it is finished. I use 4 methods for that, each calling the other, when it is finished.
(like one doing loader.load(urlRequest),
then loader.addEventListener
(Event.Complete, nexthandler) and so on
Now, when I call back to my document class from the last of these 4 methods it works just fine. But when I try skipping the first two methods (since I now need only one xml-File) - my try/catch-statement suddenly complains: TypeError: Error #1010! Like it needed more time to establish the instance of the document class or something similar strange.
View 4 Replies
Dec 19, 2010
I have a main document class with another class instanciated (mouse follower.as) within it. I want the mouse follower class to access a stage instance. How is this done?
View 1 Replies
Jun 14, 2007
access one instance of a MovieClip on the stage (blue_mc) from within the class file of another MovieClip (red_mc).e.g. One instance of "Blue" on the stage called "blue_mc", and one instance of "Red" on the stage called "red_mc". Both symbols are linked to class files (Blue.as and Red.as).In Red.as, I set up a function to listen for a mouse down event. When this is triggered, I want to move the instance blue_mc. At the moment, though, I can't seem to get a reference to blue_mc.I've looked into the new stage and root properties, but even though blue_mc is on the stage, it cannot be accessed using stage.getChildByName( "blue_mc" ) either.
Code for Red.as:
Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
[code]....
View 6 Replies
Nov 15, 2010
I have declared a object in my 1 st frame of application.
ActionScript Code:
var objTest:Test = new Test();
I am tring to access the object from a movie clip. Movie clip is located in frame 2. I am getting error
ActionScript Code:
this.parent.objTest.IncrementCount();
trace(this.parent.objTest.QuestionCount);
1119: Access of possibly undefined property objTest through a reference with static type flash.displayisplayObjectContainer.
How to access a object instantiated at root from a movie clip.
View 1 Replies
Feb 25, 2010
I have declared a object in my 1 st frame of application.
ActionScript Code:
var objTest:Test = new Test();
I am tring to access the object from a movie clip. Movie clip is located in frame 2. I am getting error
ActionScript Code:
this.parent.objTest.IncrementCount();
trace(this.parent.objTest.QuestionCount);
[code].....
View 4 Replies
Jun 22, 2011
I have created some (TextInput, ComboBox, CheckBox) Component instances (created as a public objects) in a Document class and added them to the stage.
Now I have created a custom class for a movieclip in library and instantiated it in the document class (also a public instance).
I need to access the component instances in the custom class. How to do this ?
Also, Is it a good practice to use ENTER_FRAME event frequently ? because if I can't access the above components instances in the custom class then I will be left with no choice but to use ENTER_FRAME event in the document class every time I need to change some value in the components...
View 7 Replies
Oct 7, 2009
I'm with a doubt that is crashing my project over here.
Example: I have my class....
Code:
package {
public class SoundPlayer extends CheckVersion{
public static var saveId:Object = {};
public function SoundPlayer($url, $vars):void{
trace(saveId[$url]) // here the class return to me the first call
[Code] .....
If I access SoundPlayer.Init(), I pass my URL and my variables, I got the first access, but for example, when I save this variables on my constructor and want to access again with a different call, the flash output returns like "null", like... SoundPlayer.PlayInit("myId");
take a look bellow
Code:
public static function PlayInit($url :String):SoundPlayer {
trace(SoundPlayer.saveId[$url] as SoundPlayer);
return SoundPlayer.saveId[$url] as SoundPlayer;
}
How I can access this variables in second time?
View 1 Replies
Nov 16, 2010
I have declared a object in my 1 st frame of application.
ActionScript Code:
var objTest:Test = new Test();
I am tring to access the object from a movie clip. Movie clip is located in frame 2. I am getting error
ActionScript Code:
this.parent.objTest.IncrementCount();
trace(this.parent.objTest.QuestionCount);
[code].....
View 3 Replies
Jul 25, 2010
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.
package extras.utils {
import flash.display.Sprite;
import flash.display.LoaderInfo;
[code]....
Should I use this FlashVars? and if so, how?
Or is there an easier way to access the variable?
View 1 Replies
May 4, 2010
Say I define a variable in a class file:
public var container:sprite;
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?
View 5 Replies
Feb 16, 2006
I'm writing a little application to run a course, and the engine creates the navigation menu putting labels in the button etc...
So, as far as I change things like a dynamic text that's on the stage with something like
mybutton.itemText.text = my_xml.childNodes[0].childNodes[index-1].attributes["Label"];
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...
View 4 Replies
Jun 18, 2009
Say I have a class called Ball (movieclip) and I create a number of instances of it. There is a static variable, say, ballArray and need to access that from a different class, say, Bat. How do I go through with it? Can I access that using the class name itself (Ball.ballArray like in Java)?
View 1 Replies
Jan 19, 2010
having trouble accessing variables from the main timeline from within my class...this is a function within my class...(not the constructor function)
Code:
public function createPanorama():void {
var url:String = "../../../panorama/panoramaImg/fenway.jpg";
[code]......
View 6 Replies
Apr 11, 2010
i'm trying to assign a parent's variable from the parent's child
//Parent
public class Main extends Sprite
{
public var selectedSquare:Sprite;
[Code]....
i'm receiving this error, but i'm casting parent from displayObjectContainer to a Sprite so i have no idea why it's not working.
1119: Access of possibly undefined property selectedSquare through a reference with static type flash.display:Sprite.
View 2 Replies
Aug 16, 2010
I am hoping someone can explain about subclasses accessing variables from the super class. I found that the subclass can only access variables which are set in the constructor of the super class. Is there any way around this?
[Code]...
View 3 Replies
Jan 27, 2008
class fial
{
public var num = 5;
[code].....
View 1 Replies
Oct 11, 2010
I was wondering if there is a simple way to access variables from a class object, where the variables are not actually a part of that class. So if you had an array defined on the first frame of the stage, and added some elements to it, you could use the methods of the custom class to manipulate the array's data.
Stage Frame 1
Code:
var myArray:Array = new Array( "apple", "banana", "pear" );
var myClass:someFunctions = new someFunctions();
myClass.addValue( "orange" );
myClass.sortValues();
[Code] .....
It might not seem logical as to why you would ever want to do that, but it's a very simple example, and it's the means I'm after, not the result. I'm creating a list of functions available to execute by a user via an input field. To keep things simple I made them the methods of a class. The issue, however, is that these methods need to manipulate objects which are on the stage, added and removed by a separate controller class. Passing the objects by reference to the class as a parameter would not be viable with what I'm trying to do either.
View 4 Replies
Apr 27, 2010
I have flash (AIR) application running on a single controlled system (there is only one computer running it and nobody has access to it).I will host some files on Amazon's S3 and I need to make sure that only my flash app running locally on that computer can access those files.I'm wondering what the best (most secure) approach would be for doing this.My initial thought is to make the files on S3 private and store the secret key on the local computer running the flash app. Then when I needed to access the files from flash I would send out an authenticated query string with some expiration time. The only problem with this is that I don't know how to generate the S3 signature in flash. Also I'm a little skeptical about storing the secret key on the flash machine (even though it's a privately owned machine with no other users using it).Is there a better approach perhaps?I have access to a server with PHP, so I could maybe use that as some kind of proxy, I'm just not sure how while keeping the file access secure and not creating a bottleneck through the web server (as opposed to direct access to S3).
View 1 Replies
Aug 28, 2011
Here's my actionscript (compiled with mxmlc, embedded into html, and the functions are called with js):
[Code]...
View 1 Replies
Aug 10, 2011
I'm trying access a static variable located of a super class through an instance of one of it's subclasses and I'm receiving an access of undefined property error (example of which below). Creating another static variable in the subclass and assigning the value from the super class will allow me to dot operate to it.
[Code]....
View 1 Replies
Jan 26, 2006
I've created a class that utilizes setInterval...I call it in a different class...and I can't get it to make the setInterval call. I'm thinking there's a scope problem but I don't see it.
Class w/ setInterval:
Code:
class Foo {
private var id:Number;
public function Foo() {[code]....
The function will get called but I need access to the class's instance variables inside display().
View 5 Replies
Apr 8, 2010
Is there any way to mimic the in operator, but testing for the existence of protected or private fields?For example, this:
<mx:Script><![CDATA[
public var pub:Boolean = true;
protected var prot:Boolean = true;
private var priv:Boolean = true;
[code]...
When I want to see:
pub: true
prot: true
priv: true
bad: false
View 2 Replies
Feb 21, 2007
ActionScript Code:
class Vector2d extends Math {
private var x:Number;
[Code]....
I can't seem to get my private variable, x, to be private. From my understanding of private variables, tracing n.x should throw an error, and adding 150 should throw an error. I've tried changing the variable's name, and the cast type, to no avail. The first trace goes through, the addition goes through, and the second trace goes through.
I'm new to classes, so I could easily be overlooking something vital. But the vars need to be private, because I want to use get/set to update the variables when one or another changes. For instance, if 50 is added to the y value, the magnitude and unit vectors would change, so I want to update them using getMag and getUnit. That whole system would be thrown off if the user had direct access to the properties.
View 11 Replies
Jun 13, 2010
i've never tried to do this before, so my head a swimming a bit. i'd like to have a public boolean called enabled in myClass custom class. if it's called to be changed, how do i trigger a function from the change? should i add an Event.CHANGE event listener to my variable?
View 1 Replies