Flash :: Use A Method Of A Class Inside A Callback Function ?
Sep 13, 2011
When you call a method of a class inside a callback function, you can not use this object.To call the method, in javascript, I declare that variable, assign this to that, and use that inside the callback to call the method of this.In actionscript, do I have to do the same way as I do in javascript?The following code is the example to use that to call a method inside callback.Are there more simple way in actionscript?
I have a simple quesiton about class, method and functions inside a method and class properties. I created a new class form my custom component.. But upon developing it I found out that you can not access a property inside the function which is also inside a method..
Example Code: class myClass{ private var myProperty:Number = 1; //default is 1 //constructor public function myClass(){ }//Method [Code] .....
What I want to do is to access the property inside the method.. I also have a work-around still i cannot point a certain variable to a property of my class inside the method's function..
I have a flex app and I am adding a callback method like this:
private function init():void { ExternalInterface.addCallback( "playVideo", playVideo ); }
[code].....
However if I uncomment and run the alert first. I get no error and it works perfectly.My first thought was that the alert was buying time until the script could execute, so i tried to run the script inside a setTimeout() but did not work.
I created an array of objects and put an event listener on each of them. My problem is that when the object is clicked, I want to access a method inside the object's class but I do not know how to reference its position in the array. This isn't very clear but hopefully my code will make it clearer.
This line is inside while loops and puts an event listener on every square.
[Code].....
How can I know which square has been clicked?
Note: e.target returns the following error:
ReferenceError: Error #1069: Property placeChar not found on flash.display.Sprite and there is no default value.
I have been trying to add a movieclip to my .fla file from a class.my main fla file: main.flaactionscript file: script.asthey stay in the same directory.script.as file as follows:
package { import flash.display.* public class MyClass extends MovieClip
I have to know if a public method has been called from outside the class or from inside. The reason is that depending on this, one of the actions to be executed in this method vary a bit.
I'm having some trouble finishing an interface i'm working on,the function indica() adds a menu listing of items (indicadores) inside a mask because its too large, and i added a scrollbar that allows to scroll through the items but now i need to add the buttons inside the movie clip indicative,i can add symbols and buttons, but i'm having trouble having them call functions inside the same class that the function indica() is running.[code]
In 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{ public class Character{ protected var _hp:uint = 50; //Character Health Points protected var _power:uint = 5; //Damage dealt
[Code].....
I`m instancing a Character and a Player in the Main Timeline, all in frame 1. When I use: ""player.attack(character)"" it works fine by itself.
So I added the if (defender._hp <= 0) this.win() which gives me the following error:
1061: Call to a possibly undefined method win through a reference with static type Character.
"defender" is a Character instance, "this" is a Player instance and "win()" is a Player method. I try to call the Player method inside a Character method using the Player instance adding the "." and his method name
Do I really need to define the win() function in the Character class? Is there a bypass to use a subclass method in a parent class method if it`s called from an instance of the subclass?
I was wondering why my current code for calling a setInterval on a function doesn't work inside my class.I have this code inside one function, calling a second function.
The selfReferential keyword refers to the current class,but was defined previously (selfReferential = this; ).I get no errors, but the dupe() function is never called.and I had the selfReferential variable replaced with the this keyword at one point as well.
I'm totally new to Adobe Flex Builder 3. I've been assigned a fully functional project but when I want to add the simplest function to any class, I always got the same error : Call to a possibly undefined method through a reference with static type
For example, in some random class there is a function defined like this : public function GetID() : String { return m_strID; } If I try to define a new one like below : public function GetIDFoo() :String { return m_strID; }
And then I try to call both of them like this: trace ("This line is ok : " + oPhysicalScreen.GetID()); trace ("This line gives me an error : " + oPhysicalScreen.GetIDFoo()); [Code] .....
override a custom class method with a function expression? For instance, if I want to change the destination of a button on the fly, I could theoretically type:
Code: var new_destination:Function = function(evt:Event):void{ go_to_new_place();}; myButtonClass.mouse_clicked = new_destination;
but unfortunately that generates an error because the class method "mouse_clicked" is already defined in my class (with the eventListener tied to it). I tried using the "override" keyword in the Function Expression but that didn't work either.
For some reason I cant figure this out,I have a function thats in a method in a class..I have a second method in the same class, trying to call the function from the second methodeg:
Is it possible to call a function defined in a movie clip from a class?Here's a sample project setup I'm trying to achieve this simple feat:
func.fla - Has one movieclip "fooinst" which is library item "foo". - The "foo" library item has linkage is to the "Foo" class - The "foo" library item has one script on it's first frame:
I have the following two classes and can't seem to figure to figure out how to call a function in the top one from the bottom one. The top one get instantiated on the root timeline. The bottom one gets instantiated from the top one. How do I call functions between the classes. Also, what if I had another call instantiated in top one and wanted to call a function in the bottom class from the second class?
1- i have class and i called its before and its running on runtime. i need to call function inside this class from another class, but without call the first one again, because if i called it, it will run default class function again is this doable ?
i want to call an external function inside a class. thats the code;
in checkConnectionStatus function,
this[_funcNameForSucceededCon].apply(); doesnt work because "this" is the class, not the Application. How can i reach Application at this time or what can i do?
Code: class className () { //constructor function className(targetmc,linkId) {
[code]....
My question is how can I set up an interval when I click on a button that is created from within the class.
I need my function updater to keep repeating untill I clear the interval.The only way I can figure out is to give the full path like this._parent._parent.instanceName.updater inside the setInterval, but although this works I think is just dumb to hardcode the instace name of the class. I could of course try to pass the instance name as a parameter, but I would really love to find out the smart way to do this (by the book).
How do I keep the cycles active, and also call a function at the end of each cycle/tween? Right now I can remove the soundHammer call back and the tween will continue to cycle, and if I remove the cycle soundHammer is called properly, but obviously it doesn't cycle anymore.
Lets say I add a callback function to be run every frame the AS2 way. Code: this.onEnterFrame = myFunction; If I add another enter frame listener, will this replace the old one, or add to the old one, so both functions will run when frames are entered? And how do I remove these listeners?