ActionScript 3.0 :: Declaring And Using Static Method/function
Sep 2, 2009
I wanted to use a couple of stand-alone function/or static methods by declaring them in the external *.as file and import it.
The problem is, when I import it, I had to instantiate a new class from imported class to use any of these functions which is not necessary in my situation, I just wanted to be able call these functions.
It (AS) does not allow me to declare those functions outside of class declaration, (tried with static keyword in front of those functions just like in C++).
I also tried to declare the class itself with static keyword (also just like C++) but AS also does not allow me to do that.
Remember whole points is declare couple of helper functions in external *.as file and use it over and over.
View 5 Replies
Similar Posts:
Sep 9, 2009
Is it more common to use a function for program utilities or a static method?
[Code]...
View 9 Replies
Sep 27, 2011
I'm creating a utility function for debugging/logs, which I access by importing the class and calling
new Log(params);
Alternatively I change the function to a static, and rename it to It,
then I can call it by Log.It(params)
I'm wondering if it possible to set it up so I can simply call Log(params) similar to the trace command?
function:
package
{
public class Log
{
[Code]......
View 1 Replies
Mar 29, 2011
public var blob:Blob = new Blob()
addChild.child(blob)
i get this error Call to a possibly undefined method child through a reference with static type Function.
View 4 Replies
Feb 19, 2010
I'm tryng to make a public static method call another method, but Flash throws error 1180, sayng that the method called by the static method is undefined.
Code: Select allpackage
{
import flash.display.MovieClip;[code]....
View 2 Replies
Apr 30, 2011
I am writing a program that requires the use of 36 boolean variables with different names (e.g. box1, box2...): does anyone know of a quick way to optimize this program.
View 5 Replies
Sep 14, 2010
two classes, both extend EventDispatcher. Static method in 1st class calls instance method in 2nd event not getting caught. [code]also, since dispatchEvent() is an instance method, is there any way of calling it without first instantiating the class? i expect not.
View 2 Replies
Nov 27, 2009
I have a set of Cue Points in an FLV I'm playing. It's an interactive quiz, so the idea is that flash will change a variable, theAnswer, to a different letter depending on which question it is. The answer to question 1 is B, question 2 is D, etc. Either the cue point event listener isn't working, or else it is working and Flash isn't declaring the variables. 1120: Access of undefined property theAnswer. I literally can't find a single problem with my code. I have an almost identical Event Listener further down which works.
[Code]...
View 4 Replies
Jul 27, 2009
is it possible to declare function this way
ActionScript Code:
function startShake(e:MouseEvent, num1, num2):void
what i mean is it possible to send to the function not only en event but also a variable and a second question how can i access
ActionScript Code:
function stopShake(e:MouseEvent):Array
this array that function return.
View 1 Replies
May 5, 2011
I want to create a vector, then call a function that populates that vector with arrays. Fine. The only catch is the function itself will declare new array variables to put into the vector, but are these new array variables private to the function only?e.g. something like this
ActionScript Code:
public var vec:Vector.<Array> = new Vector.<Array>();
private function populateVec():void {
[code]....
Is this "kosher"? a was declared in the private function but added to something outside the function..?
View 4 Replies
May 18, 2011
Basically, what I mean is I i have few layers of classes, that calls and change something on the 1st(root) class. In between the process I have to use static var and static function.But when I want to run a function which does not change any variables, for example:otoAndStop(someFrames), I need to make the function a static function too or else there would be error
Code:
1061: Call to a possibly undefined method checkStatus through a reference with static type Class.
[code]....
View 4 Replies
Jan 6, 2010
Ok, so I have a bit of a mess here (Which I'm probably not doing right anyway, which could be my problem...). I have a document class, I'll call it as Body.as, that creates an object from another class known as Headgear.as. There are also other objects created from other classes, or will be in the future. Now, amoung all this, Headgear.as and all of the other classes Body.as will use to make objects require the use of dragging functions (starting and stopping dragging). On stopping drags, position checks are then made to compare a particular hidden movieclip with the dragged MC.
To try and save myself some hassle (from making the same functions over and over to ensuring that when the objects are created I don't need to send a complete crapload of variables just to ensure the position checking function would work), I had the functions for the event listeners (Which are set-up on the draggable MCs in Headgear.as) just direct to functions in Body.as
[Code]...
View 6 Replies
Nov 22, 2009
Alright, so I have a class that is linked (via the linkage panel) to a scrollbox class. I'll paste the class here:[code]Ignoring the formatting, the commented out functions are the ones causing the issue. Adobe says that it's a static class and I can't use non-static functions. The way I wanted to use it was:
1. Call the page button generating function above.
2. In the main code in my program is this line:scrollbox.setClickFunction(historyContent.generate Page);So when the buttons that are supposed to be generated are clicked, the scrollbox class can call the History pages generatePage function and pass it which page to show. (I did this because there was a lot of text and a limit on how much would display, so small chunks sounded logical).
3. In the onClick function (which I haven't finished yet because the rest wont work), when you click one of the buttons it calls the set function. Its that simple.
View 4 Replies
Jul 25, 2009
why can't i get a return value from this function because i need those values to reset a image to it's previous position.
PHP Code:
Cam.addEventListener(MouseEvent.ROLL_OVER,animIn);
trace(animIn); // here is where i got a problrm
function animIn(evtObj:MouseEvent):Array {[code].......
why i can't do it like that what i mean is why i can't declare this function that way because when i do the fallowing error occur:Ereor #1063
View 5 Replies
Feb 25, 2010
I know that as long as a I declare variables inside a function I can only call them as long as the scope of the function is active. Outside of that function the variables don't exist. Is there any way I can create those variables inside a function and use them outside of it?
View 1 Replies
Mar 18, 2009
I'm trying to create a unique variable and reference to it with myRewind for some button functions.
I'm trying to create this rewind+variable as the unique identifier but it just seems to be using myRewind as the variable and overwriting it.
Code:
//Setup subsection rollovers
function createRollover(myContainer, rollName) {
btnName = rollName+"_btn";
mcName = rollName+"_mc";
[Code]....
View 2 Replies
Jul 30, 2009
I am trying to send a value from one of my xml nodes (<marker>) by declaring it in a function 'showData' as a variable 'XMLMarker'. If I trace this value (XMLmarker) it returns the right data found in the node <marker> (which is 'myMarker_mc'). However, I need to tell the stage that myMarker_mc is a MovieClip...please see the 'PROBLEM' stated in the code below.
[Code]....
View 0 Replies
Sep 30, 2010
While this is similar to another post, that post (does not indicate how to perform this (if it can be done) without instantiating an object. Also, without success I have tried multiple variations on the theme of:
class[method](arg)
class[method].call(arg)
method.apply(class, arg)
I have used Reflection in both C# and Java. BTW, the code that I am attempting to get to work in Flex is mirrored in both those languages and works as expected.
Non-functioning Flex Code:
private function ipMethodTester( ipMethodName:String,
shouldPass:Array, shouldFail:Array):void
{
[Code].....
View 1 Replies
Mar 29, 2011
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 Replies
Aug 6, 2011
When 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 Replies
Jul 15, 2009
I 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.
View 6 Replies
Jul 27, 2009
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
Mar 10, 2012
I have been away from actionscript for a long time and not 100% why this is happening, I will simplify the class below[code]...
call to a possibly undefined method through a refernce with a static type?
View 1 Replies
Jun 29, 2010
I have a bunch of functionality which is going to be used throughout the application.I already have some utilities which work ok such as changing an AS3 object into XML.public static function convertMyObjectToXML(o:Object): XMLThis can go in a UTIL class somewhere.nother thing i would like to do is create a "createDirectory" via php. public static function createDirectory(name:string, path:String): voidThe problem is, in order to get the response from the server, i need to listen for the load to complete (or fail).So am i right to think that static methods are not possible or desirable here? How else can i solve the problem of reusing such a method throughout an application?
View 0 Replies
Sep 21, 2011
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].....
View 4 Replies
Nov 12, 2009
Let's say I have a utility class that contains a static method. This method runs some math on the arguments passed to it, then returns an Array.
Example:
Code:
// within the utility class
public static function getPoints(num:Number):Array {
var ar:Array = [];
[Code]....
View 2 Replies
May 22, 2009
Let's say I have a Custom Event Class, and it has several Event types stored in static Constant:
[Code]...
Is there an easy way to validate that the type passed to the Constructor is one of the Static Constants of the Class, without having to check it against each value?
View 5 Replies
Sep 23, 2009
this is the function i want to turn in to a static function. just dont know how to make it a static function and call it from other classes. i think this would have its own file.
[Code]....
View 2 Replies
May 13, 2011
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 Replies
Jul 24, 2010
Why static method cant access private properties in the same class?
View 1 Replies