Actionscript 3 :: Encapsulating A Static Function?
Jun 11, 2010i would simply like to encapsulate a function in it's own .as file, but i can't quite get it.
[Code]...
i would simply like to encapsulate a function in it's own .as file, but i can't quite get it.
[Code]...
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]....
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]...
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.
I'm trying to encapsulate this game (actionscript below) into a movieclip so I can build the menus easily. The filename is MemoryGame.fla The class file is called MemoryGame.as It's Actionscript 3 using cs5 But when trying to create the movieclip with the name of the class file I receive this error: "Please enter a unique class name that is not associated with other library symbols". in my library nothing else is linked to it though... Im doing this from a tutorial book and this is what it says to do but is there something obvious i've failed to notice? Here's the code:
[Code]....
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?
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]....
i'm trying to modify some code and can't figure out what the issue i'm having it. this is the(shortened) code:
public static function Lose():void {
trace("OVER!");
Clock.stop();[code]...
this is the error i get: 1180: Call to a possibly undefined method OverIt.i just want to call a function from inside of the public static funtion.both function are inside this class:
public class Game extends MovieClip {
}
I would like to do the following:Have a few objects (e.g. 20 of them), each time I mouse over any one of them, it moves up and each time my mouse leaves, it moves down.[code]...
View 3 RepliesI would like to know, in Flex 4.5.1, if there is a way to create a static variable in a member function, something like bellow:
public function myFunction():void {
static test:Object = null;
}
Is it more common to use a function for program utilities or a static method?
[Code]...
I have some problems working with "static function"For example:
Code: Select all public static var someText:TextField = new TextField();
public static var FORMAT:TextFormat = new TextFormat("Arial", 12, 0x000000);
public static function myText():void
[code].....
Just transitioning into object orient programming and I got stuck trying to create textField using static function. I searched online about this and none of them were useful. I dont want this to be just public function because then I cant access this function from other classes. I would like every classes to access this function so I need it to be static.
package {
import blahblah
public class example extends MovieClip{[code]..........
Can i create static function in a class in action script 1 ?
View 1 RepliesI need Mouse coordinates inside a static function. It isn't a mouse event function and there isn't anything passed in the function.
// Main class
MyClass.something();
// MyClass
public static function something():void {
// Get Mouse Coordinates
// myclassclip.x = mouse coordinates
}
I've created a class to hold data in static vars with getter and setter methods. The class in never instantiated, i.e. var obj:MyClass = new MyClass();.[code]
View 5 RepliesI 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.
I've summarized my issue in the following [code]...
1119: Access of possibly undefined property mc through a reference with static type Class.
Is it possible to call/envoke a public static function from JS? I can't seem to get it working and Im almost certain it cannot but I thought I would ask the community.
View 2 Repliesi have two classes , and i need to call static function from one class to the other. also when i call this static function i need access the local variable of that class. Class Test2: Quote:
[Code]...
when i run these class i get the following error Test2.as(18): col: 10 Error: Access of undefined property testVar. this function works if i change [testVar] to a static variable , is there any other way to make this function work other than making the [testVar] variable to static?
I'm using exanimo's statemanager class but I dont know how to use this function:
public static function set defaultStateID(defaultStateID:String):Void
how do I call this function?
I have 3 external .as files...
Game.as
Checker.as
CheckerP2.as
In Checker.as I have the following function...
static function checkPossibleMoves(){
...
}
I'm able to call and execute this function from Games.as using the following code...
Checker.checkPossibleMoves()
But whenever I use the same function call in CheckerP2 the function does not execute?
Does anyone know how to addChild(aMovieClip) to stage by using a static function, like:
public static var player
public static function LoadPlayer()
{
GameEngine.player = new Player
stage.addChild(player)
}
(Or better yet tell me how to run functions in different class without creating instances of them or using static function )
I have never encountered this problem before.
I have a support class called ICSNAArrays.
It contains only static functions.
In my main class file I have imported it and then when I try to call one of the functions I get a compiler error that says there is no method with the name 'ICSNAArrays' I don't understand this. There are no errors importing it. All of the spelling is correct I am 100% sure on that. [url]...
I'm currently writing a class where I'd like to call the class constructor without having to instantiate the class itself. Something like this : Class:
[Code]...
trace(testString); //wil trace the text "test test123" Is it possible to somehow achieve this? When I write the costructor method like "public static function ClassName" it fails. Is there any other way?
I'm wondering if its possible in flash to be able to call a static class function via its name as a string. I know for you're usual case you can do this to call the function 'func'
Code:
this["func"]();
func():void
{
trace("I'm a function");
}
However I'm wanting to do this from another static function and in a static function you obviously can't use the 'this' keyword. I've tried just omitting it, or replacing it with the class name but neither work.
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'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]......
Is there any way that you can have dynamic variables inside of a static function considering that you can't use "this" inside a dynamic function.
What I am trying to do:
public static function convertToDynamicString(pString:String):String
{
if(pString == "" || pString == null) return "";
[Code]....
Is it possible to reference a control in an application from a static function?
What I have is a Viewstack containing VBoxes stored in separate controls. Ex:
<mx:ViewStack id="content" width="100%" height="100%" resizeToContent="true">
<controls:Login/>
<controls:Dash/>
[Code]....
Once I get logged in on my login control, I would like to change the selected index of my ViewStack. From my outside controls, I cannot reference my ViewStack by name. I can reference a public static function from an outside control however I cannot refer to the ViewStack from within that function.