ActionScript 3.0 :: Static Method Can't Access Private Properties In Same Class
Jul 24, 2010Why static method cant access private properties in the same class?
View 1 RepliesWhy static method cant access private properties in the same class?
View 1 Replieshow bad is this practice? I am having trouble getting to some stuff so i am taking the easy way out
Code:
private static var _interrupted:Boolean;
public static function setInterrupted(value:Boolean):void{
_interrupted = value;
}
I have written a framework that facilitates RPC calls between AS3 and PHP 5 called FlashMOG. I recently got a forum request that has introduced a pretty bizarre question regarding access control. This will be a lot easier to discuss if you have access to the FlashMOG 0.3.1 client source which is here:
[code]...
The basic idea is that I have a FlashMOGService class which has an RPCSocket member that it may share with other FlashMOGService objects. The idea is that you can create two distinct FlashMOGService objects and have them both connect to the same host/port via socket. I use my special RPCSocket class for two reasons:
1) Let developers use one port but separate functionality into two distinct services...a form of multiplexing i guess
2) RPCSocket adds functionality to the standard Socket class that works to serialize and unserialize data and get it where it needs to go. The essence of the problem here is that created a class with a FlashMOGService object as a member and has tried to assign a private method of his class as an event handler to the FlashMOGService object:
[Code]....
My initial thought is that this should be fine because it's all done within the class. However, when I consider the monkey chain that results in this function being called, it seems almost logical that it wouldn't work. The problem is that the browser freezes when a socket message arrives that tries to call the service's client method, _service.client.firstClientMethod. This client firstClientMethod is attempted when data arrives from the server on the Socket (an RPCSocket, actually). The RPCSocket class deserializes the socket data and extracts an array with a service name, a method name, and an array of arguments. It looks into its own private class variable (an array of services using the RPCSocket) and tries to invoke whatever function was assigned thusly:
[Code]....
I'm guessing there's some kind of infinite loop going on to check access control for the various intertwined classes.
Error: Access of undefined method getStatus through reference with a static type Class.
Here's what's happening in the code. I'm trying to create a User class that is instantiated at the start of my app. I want the User class to have properties like mainStatus, with helper methods like setStatus etc. Pretty simple.
so on my HardDisk I have my flash_working folder with all my flash projects. I created my class file/package under the directory com.mypackage
[Code]....
That's all the code I have.
If I try to access the public var mainStatus through user.mainStatus that gives a similar error saying:
Error: Access of undefined property mainStatus through reference with a static type Class.
I am writing class that extends adobe air PNGEncoder,
I want to use the writeChunk method, but it seems to be private static and i cant seems to use it with my code But it gives the error as below
[Code].....
I've heard it's considered best practice to keep all class properties private and to change them using getter and setter methods.
View 5 RepliesI have .fla file where I have instantiated an object of a class( testclass.as ) like this in frame 1
[Code]...
I have this sample class
Code:
class TestPrivate{
public function TestPrivate(){};
private function getGo(){
trace("can execute");
}}
And then after instantiate I just calling the method...for testing the "public" and "private" keyword purposing only...
Code:
import TestPrivate;
var obj1 = new TestPrivate();
obj1.getGo();
The result is still can be execute even though I put the private keyword in front of the methods. So what's the private keyword stands for actually...I thought it prevent been get accessed from outside...
ActionScript Code:
//such is a simply version of the hierachy of my project
// in DrawingTool.as[code]........
it's settled, why? must I give the explicit and full referrence to access the static property.
here is a snippet of my code in an as file
ActionScript Code:
class PoolBall extends MovieClip {
private var poolBall:MovieClip;
[code].....
is there a difference between classifying a function 'private' or 'private static' in a singleton? It seems that they both do the same thing. Maybe some difference in performance?
[Code].....
I have an object on my stage, called obj.I also have a class called "Physics" which contains a bunch of methods for physics, such as inertia, gravity, and bouncing off walls. In order to do some of these,I need access to the stage.stageWidth and stageHeight properties.My code is as follows:
public function wallBounce(obj)
{
this.stageRef = stageRef[code]...
This is supposed to check if the object's x value is greater than the stageWidth or less than 0. When I run this code it says:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I am a semi-newbie programmer who is completely self-taught and have no clue what is causing this. I spent a bit googling it, and I think it has something to do with scopes,.
I'm kind off oblivious as to what I'm doing wrong here... I have two classes: - Alley - AlleyCat
[Code]...
i have to read the current class name inside a static method. For non-static method it's easy i just call getQualifiedClassName(this) but inside a static method this is off course invalid.
View 2 RepliesWhen I type a class name without new before, FlashDevelop does not show autocompleate. Is it a way to enable that feature? (do you have the same issue?)
View 2 RepliesI have a pointer to a Class object like so:
var temp_class:Class = getDefinitionByName(getQualifiedClassName(some_obj ect)) as Class;
I want to use it to call a static method 'can build' on that class, like so:
function can_build_ot(c:Class, qualifier:Object):Boolean {
if (c.can_build(this, qualifier)) {return true;}
return false;
}
When I do this, Flash CS4 AS3 tells me
1180: Call to a possibly undefined method can_build.
If all I have is an instance of an object, can I call a static method of its class? For fun, let's say I don't know what the name of the class is, only the name of the static method.
View 3 Replies My method has been passed a class instance, but it was typed through an interface so I'm not 100% sure what class it is. I'd like to attempt call a static method on that instance's Class.. is there an easy way to do this without being forced to pass the class along as well?
Something like this:
ActionScript Code:
public function foo(myBarInstance:IBar):void {
var barClassPointer:Class = getClass(myBarInstance);
try {
[Code].....
Is there a way to make an static method act over an object of its class that is already on the stage, without using the keyword "this"? I mean, like "generic object of this class: do what I'm telling you to do, wathever your instance name".My goal is to create an method that get called by any object of this class, based on the changing on the value of an external variable, but since I cannot use the "this" keyword to reffer to each instance, I could not figure out a solution.
View 1 RepliesThis .as file was working fine yesterday and now Im getting this error.
View 3 RepliesIn the following code (thoroughly debugged) the first case (1) in the switch is met and a new instance of BannerSingle is assigned to retVal (the return value). Unfortunately, while the second case (2) is never met, the assignment therein to retVal takes place and I can't compile. When I comment out the assignment to retVal for "case 2:" everything works fine.
I've tried using an if/else instead and I still get the same odd behavior. Also tried a number of solutions involving separate variables, etc.
package fl {
import fl.IBanner;
import fl.Banner;
[Code].....
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.
I wrote a singleton class to keep track of some variables across my application.
I am getting a syntax error that I can't figure out, I am sure that I am missing something simple but it's been one of those days. Anyone see something wrong with my code?
The error is 1061: Call to a possibly undefined method setResult through a reference with static type Class.
My function in my singleton class
public function setResult(resultNumber:int, value:int): void
{
switch(resultNumber)
{
[Code].....
I've summarized my issue in the following [code]...
1119: Access of possibly undefined property mc through a reference with static type Class.
I have the actionscript code here for a bubble popping game. When the game starts, bubbles fall down from the top of the game to the bottom and score is kept for the most bubbles clicked or popped in 30 seconds.The size of the bubble is defined by the initialize method in the code, and uses ToString() to calculate the score. ToString gives me a 1061: Call to a possibly undefined method Random through a reference with static type uint. This error which I cannot figure out where it comes from.[code]
View 4 RepliesIs there a way to change private static field of an alien class?[code]...
View 2 RepliesError 1061 Call to a possible undefined method addEventListener through reference with static type Class
source:buttonsMenu.addEventListener(Event.ENTER_FRAME, moveMenu);
I get the above error. I did actually change a little code because I put it in it's own class.I call the below ShuffleArray class in my main doc class as follows:
ShuffleArray.shuffleKnuth(definitionsArray); [code].....
I've been using Adobe Flash CS4 for a couple of days. I've drawn a worm, with eyes and a mouth and these pieces are all MovieClip symbols. I have exported them to actionscript with the class name being the same as what they are (ie. the mouth MovieClip is exported as mouth). The mouth has 2 frames, one smiling and one frowning. I need to mouth to stay smiling at first, so in Frame 1 actions I wrote:
View 2 RepliesI see where i was going wrong however when i change the instance name like you said i 1120: Access of undefined property snakePart. all of this code btw is at document class level and the movieclips are in the library not on stage
View 3 Replies