ActionScript 3.0 :: Defining Variable Types In Functions?
May 2, 2010
if defining variable types in function parameters gives any speed boost.
e.g
ActionScript Code:
function DoIt(param1,param2,param3):void
{
[Code]....
is there any performance difference between above functions. in theory compiler should be able to manage memory more efficiently when knowing what data to expect, but is it so in flash
What I am trying to do is kind of odd, but I am wondering if anyone can come up with a clever way to do what I want to do. Basically, I want to re-define a named function at runtime. I can do this with anonymous functions, but I can't figure out a way to do it for named functions. I want to do this so that I can implement a "spy" functionality on an object for a testing framework (a port of Jasmine to Flex).
Take, for instance, this class:
public class TestClass { public var anonymous:Function = function():void { trace("original anonymous");
[Code].....
Can anyone more clever than I come up with a way to hack this? Can the bytecode be hijacked? Something?
I would like to know if this is actually possible in AS3. I'm not really fluent in Java-style programming, but very used to C++'s .cpp and .h file system. Right now my functions are defined where my class is defined, so as you can imagine, my classes look incredibly untidy and disorganized.
I�m trying to use Listeners to capture the MouseUp event based on Helen Triolo�s sample at [URL]I reused her code and loaded the listener�s array (with MC names that will listen to the MU event) from a textfile.My problem is that I don�t have these MCs on the _root. They�re located deep in the MC hierarchy, this way: MCComponent-->MC1-->MC2-->MCs I want to address for listening (I have about 250 MCs in this level of depth which I want to to address for listening)So, when defining the MouseUp function for each MC to respond to, I couldn�t address the MCs. I tried in different ways without any result.
This is the code:
// set up responders for each listener // listeners is the Array with MC names which I loaded from // the textfile for (var i in listeners) {
[code].....
Is there any way of making this work? Is there something missing in this code ? Note: I cannot put these MCs on the root because of other functionalities that they need to accomplish...By the way..., what about RollOver and RollOut ? Can they be captured too ? I�ve read about capturing MouseUp, Move and Down but not Rollovers...
I want to define functions to move a movie clip around the stage, my code works when i define it STRAIGHT to the movie, but when i define it as functions it doesn't.
I'm making a platform game where all of my level components (ground, background etc.) are within an array called 'levelArray' so I can move all the elements the same amount at the same time. I'm just starting to implement my second level, and I need to change 'levelArray' to contain different level elements. I've tried to put an 'if' statement to change the definition of the variable:
Code: var cnms = this.cNames.split("|"); myDP = new Array({cnms[0]:"Chris", cnms[1]:"Priceless"}, {cnms[0]:"Nigel", cnms[1]:"Cheap"});
Obviously, this doesn't work, otherwise I wouldn't be typing this right now. How do I define an object with variable properties ? I've tried eval(), but it doesn't work either.
i'm linked a MovieClip class object to my project, and i will programatically add it to the display list. is there a difference between defining the variable's data type and not doing so? neither produce a runtime error.[code]
I'm trying to write a robust "eventMaker" function that I can run with arguments that will then create an event listener based on the arguments.
However, I can't seem to get it to pass the arguments. Functions are impossible to pass; it can't convert string versions back to functions, and passing the function as type :function just yields "function() function{}".
The same is true with strings and class definitions - if I want it to refer to an object in my other .AS file called "helloWorld", I can't make it think of helloWorld as anything other than a string or an object, and when I write commands based on it I get errors.
So how do I contain classes, functions, et al in variables that I can then reference again, in code, as those functions/classes? How can I convert a string value to something that the code will know is a reference?
This is hard to describe in a sentence, so i'll write some false code: (with incorrect syntax, of course)[code]...
Is it possible to do something like this, where I pass the name of the data Type that I want it to create and it does it within the function? And I know that with this simple example it isn't necessary to do it this way, but in the full program this would save some time and make the code more efficient.
Im working on a chess game replay system in flash, and in order to display comments on individual moves I am loading them from an external text file. Since one of the navigation buttons allows the game to skip to the last move I want to also recieve the number of the last move through this text file. After using loadvars all the comments are loaded correctly as strings but the variable for lastmove is not being recieved as a number. My ultimate question is whether there is a way to convert the text number into a real number which can be manipulated. If not, is there a simple way to load this data element individually as a number.
Code: public function foo(bar1:int, bar2:uint, bar3:String, bar4:Boolean):void{}
What I want is to have the different types of data represented by custom named types which are essentially representing the original data types. I other word, I would like to proxy the data types and have a valid function as following:
Code: public function foo(bar1:PAR_Bar1, bar2:PAR_Bar2, bar3:PAR_Bar3, bar4:PAR_Bar4):void{}
so PAR_Bar1 would proxy the `int` data type, PAR_Bar2 would proxy the `uint` data type, so on and so forth.
The reason I need this is because I'm using a debugger with a GUI that can run methods and allows changing function parameter values in real-time, the issue is that the debugger can't tell me what parameter I'm changing, it only displays the data type of a parameter. So if I need to change 10 different parameters all of type int, the debuggers display all of them as int and not by their names.
I think that if I use proxy types I can easily differentiate between parameters.
So, my question: Is it possible to proxy data types? I mean map specific data types to custom data types that would represent the base data types?
I am trying get a timer function that I can change the interval on? IE. I invoke the function for 5 frames and the last one I want to have a different delay time. It seems that for each action I have to create multiple listeners and multiple functions for? Surely there is a way, without producing a class, that I can just chaneg the timedelay? But, AS3 wants to declare the time before the function.
I don't know why the value of my variable my_str is undefined outside of this function:
loadText = new loadVars(); loadText.load("data.txt"); loadText.onLoad = function(success) {
[Code]....
ps: I tried making my_str a global function or even defining it as _root.my_str but I always get the same result..it's undefined outside the function...I need that value for something else so...
I'm trying to repeat a function that basically will attachmovie on a "tileset", an image depending on the parameter. It's called AddID(i), and currently there's only 2 valid options, 0 and 1, images showing, X and O. There's a Button, and theres an array and a function that shows an image of the tile depending on its ID value loaded from the array.
My problem is: Everything works just great as if you repeat the function by clicking again, but... When repeating the function by code, all the tiles will have the Image of the last tile added.
I'm trying to do something simple in actionscript as simple as this:- Create a variable: var urlVideo:String;- Use that variable inside a function and give it a value: urlVideo = ideoElemento.url.text();- Then create a new variable and give it the urlVideo value: var url:String = urlVideo;
Here's my code: var idVideo:String = "12"; var urlVideo:String;
How do you pass variable values between functions where the addEventListener is in the first function? I am trying to get the color value passed into my event handler. [code]...
Is it possible to pass variable as arguments for a function? I wish to update a boolean variable via a function, by passing the name of the variable to the function, like so:
Code: function ENVSegment(curSegment:Boolean, nextSegment:Boolean) { curSegment = false; nextSegment = true; } var attackSegmentIsRunning:Boolean = false; var releaseSegmentIsRunning:Boolean = false; [Code] .....
Much shorter, and easier to understand. Also, less repetition of the same blocks of code over and over...
I'm just getting into this and can't seem to make the simplest thing work! I'm trying to learn to define and call functions. I get no errors but it won't trace the variable:
I have 2 functions. Each one is being called by a different event listener. Both event listeners work because I am able to trace strings in both of them.. my problem is that i am trying to create a variable that is local to both functions. The first function "working" adds a number to the variable and when the second event listener triggers function "notworking" which retrieves this same variable called "counting" both functions are called automatically by event listeners.. how do I do this? i am stomped!
I am learning AS3 and I try to remake an SimDate game. I have studies the functions and the Steps of the game and now I try to make the Functions myself.
I have 5 Attributes: Strength Knowledge Charm Health Dollars
For each of them I have defined a variable. Now I need to make an math function. If I want to raise str: statusstrenght = statusstrenght + addstr
This code is not the original. My other code is down below. I only wanted to show the process. addstr == Math.random() *5 I wanted that the variable statusstrenght starts with 10. If I press the train Strenghtbutton the action addstr will be started and updates the statusstr with the new value. That's what I had in mind but I cant define the new value off statusstrenght + addstr. Do I have to add a new variable with newstatusstrenght or can I just overwrite the value of statusstrenght if I press the train strength button ?
Here is the code. The math functions aren't working. It is AS3. import flash.events.*; var statusstrenght:Number = 10; var statusknowledge:Number = 10; var statuscharme:Number = 10; var statushealth:uint = 100; var statusdollar:uint = 100; [Code] .....