ActionScript 3.0 :: Dynamically Naming Functions?
Aug 31, 2009Code:
public function btnU1Out_Handler (event:Event ):void {btnUOut_Handler(1);}
public function btnU2Out_Handler (event:Event ):void {btnUOut_Handler(2);}
[code]......
Code:
public function btnU1Out_Handler (event:Event ):void {btnUOut_Handler(1);}
public function btnU2Out_Handler (event:Event ):void {btnUOut_Handler(2);}
[code]......
Ok, I've been climbing the walls trying to figure this out, looked everywhere for an answer, learned a few bits and pieces along the way, but still can't do it.I've made my Class which is a little movieclip called 'block', it's fine and does what I tell it to do ie. I can reposition itstretch itotate it and stuff.The problem is.. I want to make more of them and reference them individualy so I can change the properties of them individualy ie, the x and y values etc.
for (var i=0; i<2; i++){
var newBlock:blocks = new blocks();
this.addChild(newBlock);
[code].....
or some reasons i need to create var dynamicaly.
Exemple
I have first an Array wich i want to use to "compose" my vars names
myArray:Array = new Array("aa","bb","cc");
In my final project this Array is created from a xml.
I want to do something like this, but doesn't work...
var ["myvar" + myArray[0]]:Sound = new Sound();
var ["myvar" + myArray[1]]:Sound = new Sound();
var ["myvar" + myArray[2]]:Sound = new Sound();
[Code].....
Is it possible to dynamically name a variable? Like set a certain string as a variable name wouldn't think so but just in case.
View 2 RepliesI am trying to dynamicallly name intervals and clear them. Here's my code:
[AS]
_root.onMouseDown = function() {
setMyInterval();
};
[Code]....
I am going to have a button that when you click on it it creates a movieclip and adds a certain child to it (In this case, its linkage is set as "Rifle"). Each time you click on the button I need to give the new movieclip a different instance name then the last, such as "Riflemen1", "RifleMen2" etc.. I will need to be able to refer to each movieclip seperatly in my code, such as for example:
You spawn three Riflemen.. You click on one of them, which selects it, you then click on an "Attack" button which makes only him start firing (in my case gotoAndStop(2)), you then decide you want the third one to attack and so forth..
I'm trying to name the instances of MovieClips that I dynamically load.
I tried doing this:
comp = new Comp();
// and also tried doing this--> var comp:MovieClip = new Comp();
comp.name = "comp"; // comp is the name I want the instance to be
[Code]....
i am using a loop function to generate an place instances of a movie clip on the stage. the movie clips are being used as buttons, they have text in them. here is the code
ActionScript Code:
// butAniMini is an external custom class animating the buttons
var _sideBarBut:butAniMini;
//variables to hold the first buttons x an y position
[code]...
the problem is that i dont no how to set the text in the buttons so u can change the text and add event listeners etc to them
I have a project that requires manipulation of a movie clip (swf file). This clip is called clip_mc.I have functions such as:[code]If I add to the stage the swf and call it clip_mc, then everything is fine and it all works - BUT I have a few of these files that need to be loaded when the button is clicked.I understand the loader() class and the addChild class but cant get my head around bringing them all together!so essentially I would like to know; How to dynamically load the swf and name it clip_mc so that the functions will work?!
View 2 Repliesk say i wanted to create a bunch of movieclips in a for loop but wanted to name them something different each time, how would i dynamically name them?
View 1 RepliesI'd like a generic function that can take:a) object/array containing various classed items
b) method to run on themi.e.:
Code:
var itemA = new Item();
var itemB = new Item();
[code].....
how would i go about dynamically making a function... im making a Tile Based World level editor and when the user is done editing a level, then they hit a button and a couple of for loops runs through all the tiles checking the x,y and tile type. then i want thisinformation to be parameters within sub functions within the main function. so the as would look something like this
[AS]subFunction = function () {
//do this
}
[code].....
i'm trying to call a function on a clip, but i want to use a variable that i'm sending to the clip so that when the one function gets done it knows what to do next. i just have no idea of what the syntax would be. here's a sample.
[code]...
So I've been trying to make dynamically named functions, and while it works, I've run into a couple of problems.
ActionScript Code:
var uServer:String = "irc.epic-chat.net"
var lol:String = "lolz"
var num:Number = 3
[Code].....
If I had something like that ^ what could I add to func to distinguish between whether it is being called by lolz0, lolz1, or lolz2? I was thinking whether there was something like .name I could use, but I couldn't come up with anything.
I am having trouble accomplishing the following:
Code:
var some_xml:XML = new XML();
some_xml.onLoad = function(success) {
if (success) {
[Code]....
This works fine if I use a number, but as soon as I try to use "n" within the function it throws an error. Would eval do this for me? I haven't used eval before.
So I'm finally getting to the point where my sites are just one frame with everything loading dynamically via MCs and functions and whatnots.But I'm having a problem: how does one keep track of what "page" we're supposed to be at?
My specific dilemma: I have an mc called "textframe". I have a function that does some nifty dropshadow knockout effect on that frame, so I can't display any content in it, so I thought I should use attachMovie to load different elements from the library depending on which button has been pressed. But I can't seem to find a flexible method to track which button was pressed and pass that on to which element should be loaded.
After loading the movieclips and text boxes dynamically I now need to get the movieclips to perform a unique function when they are pressed, for testing purposes I am using the getURL funciton and linking to the boxNo. This is just so I can see what is going on!At the moment they are all linking to the boxNo that is pulled from the last run of the loop.
for (var i = 0; i < loc.length; i++)
{
var boxNo = loc[i].location_ID;;
[code].....
I've been trolling through the forum and I've seen similar instances however I can't seem to get my head around how to make scripting work;What I'm trying to make is similar to an interface where users can input data into a list (myArray) should they need to remove information they can click the corresponding button to remove it, the current code is repositioning a button that's already on the field as opposed to creating a duplicate from the library
here's the full code:
stop();
//hidden hyperlink to AR
[code].....
I have a main mxml and 2 AS classes.In the main mxml I have a slider.I want to get the slider values in AS classes as I move the slider.
Main.MXML
import First;
import Second;
[Code]...
I could get the values from trace(dat)....I mean the date's as the slider changes. How could I use this changing values in function visualization()
I've got clips being attached using attachMovie (clips are in the library with linkage id's).
inside those clips are two functions. I'm trying to access those functions after I attach the clips, but not getting anywhere.
I assume that the methods of my attached clip (the functions) aren't available immediately, but rather after the clip actually 'loads' to the stage they are.
What is the best way to create functions dynamically and store them inside an Array? Obviously the bellow is wrong since the array will always trace the last value of the variable "v" (5)
ActionScript Code:
var funcContainer:Array=new Array();
for(var v:uint=0;v<5;v++){
[Code].....
I am in the process of writing a scrolling image viewer that dynamically updates from an xml file. I have written the scroll function (with a lot of help from Kirupa and other sources), and the pictures are updating beautifully, but when it comes to adding the function for the buttons I am encountering an unusual error.
Using the following code:
Code:
initButtons=function(){
for (var i in btnArray) {
var btn:MovieClip = btnArray[i];
[code]....
from this site results in the doClick function being called for each of the buttons in the btn array at runtime, and then not working afterwards.
I have a virtual on screen keyboard for a touch screen interface. I get the name of the key (Q, W, E, etc) by calling event.currentTarget.name Now each button is a movie clip with a small animation and I need to know which key is pressed so it can call the relevent movieclip..Below is the code:
[Code]....
I have been working on a Flash movie that loads variable data from an external XML file and dynamically displays the item names in a menu which may then be clicked to display other dynamically-loaded content that corresponds to the menu item that was clicked. I have now come to a standstill in the project as there is something I'd like to achieve but simply cannot work out how. This is my first attempt at working with XML in Flash and one of my early attempts at using variables. What I'm trying to achieve is; once the user has viewed the item's content, they can simply click "next" and "previous" buttons to display all of the content for the next or previous items in the XML document.
I know it probably sounds simple and I'm sure some of you could achieve this in 5 minutes (!) but I can't get my head around some of the coding. I assume previousSibling and nextSibling would come into play here as well as some sort of functions which access arrays of data for the previous and next items, but I'm just not sure how to correctly put these things to use. Rather than post my code and example images of the stage up here on the forums, I've created an html page here: [URL]
How do I execute callback functions dynamically by passing a function in as an argument to another function?
Look at this example:
Code:
package {
public class myClass extends MovieClip {
public function myClass(callback) {
[code]....
I have a series of calculations i'm doing over a bunch of objects stored in a array. Each function is pretty CPU demanding but if you only run one function, it just works fine.
[Code]...
I've got a project thats getting a bit big, so Im taking the actionscript out into separate as files. I want all the basic functions to be in BasicFunctions.as and the make a library for more specific functions. I find that a lot of people use the import statement but I cant get that to work with a simple Hello World trace, yet the include statement works fine (see attached). I understand that import/include work differently, but which is the better method? If import, then is that heavier to work with. Any rate, what's the best way to organise code when it gets to the 1000+ lines?
[Code]....
I'm trying to find a way to have global functions in my as project, similar to how flash does with stuff like the util functions (describeType()...), where you can just call the function wherever you need it. For example:
[Code]...
So when I call Test(), it prints out "hello world" fine. My problem comes in that I can't change the name of the Test function, and I can't add any other functions without compiler errors. Is it possible to have a load of global functions in one file, or do I have to split them up into separate files like in the example? Also, I know that I can make a Global class and call static functions like Code: Global.doSomething() but I'd like to know if there's a way to do it as flash does it (describeType(), getDefinitionByName(), etc), or rather, how does flash do it?
Is it not possible to call other functions from generic mouse event functions?
Code:
_root.myButton.onPress = function(){
hide();
[code]......
I have one function that puts text in a text field and makes a button goto a url onRelease.The code is like this:
Code:
item.onRelease = function() {
myButton.onRelease = function() {
getURL("http://google.com", "_blank");
}
talk = this.txt;
}
the only problem is that the button doesn't work onRelease. i think that it is because there are too many functions there, but at the same time,