Actionscript 3 :: Access Instance Variables In Closure Inner Function For This Style:this['varName']?
Feb 10, 2012How can I access instance variables in closure(inner function) for this style: this['varName']?
[Code]...
How can I access instance variables in closure(inner function) for this style: this['varName']?
[Code]...
So in AS2.0 I would use _global.variableName to create and refer to a variable that was maybe created on the stage and then needed to be referenced to inside of an instance. That doesn't seem to work anymore. Are you expected to not want to do that, or is the code just changed now?
View 9 RepliesI have defined a variable attached to a move clip via Mc.OnLoad = function *etc so is it possible to access this variable from within the move clip ?
View 2 RepliesI've created a class that utilizes setInterval...I call it in a different class...and I can't get it to make the setInterval call. I'm thinking there's a scope problem but I don't see it.
Class w/ setInterval:
Code:
class Foo {
private var id:Number;
public function Foo() {[code]....
The function will get called but I need access to the class's instance variables inside display().
I can�t access downloaded variables outside the function.
Code:
ActionScript:
var loader = new LoadVars();
loader.load("kiruppa.txt");
trace("loader.total1="+loader.total);
[code]....
the variable was loaded but I can�t access it outside the function. I got the advise to wait until it�s loaded, butI don�t understand how to do.
I can't access downloaded variables outside the function.I have had this question in forum Actionscript.org but I didn't got a reply that works for me, so I try this forum.[code]...
View 2 RepliesI have attached the actionscript file on stage, however I can't access function or variables inside movieclip. Instead I can access them on main timeline, is there a way to access function and variables inside movieclip
View 2 RepliesI am wrapping my brain around OOP in AS2. I am making two posts on two different subjects. My question here is: when should I use local instance variables, and when should I attach new properties to the instance object? (Feel free to correct my terminology.) Let's say I have a class for a scrolling background, which scrolls when I mouse over its edge. I want to put these values somewhere:
1) How wide is the border in which a mouseOver makes it scroll? This is basically a semi-constant I set it up once and keep it the same, unless the user changes it in an options menu to make the border wider or narrower. Call this scrollBorderWidth.
2) How fast is the background scrolling now? I want to track this so I can smoothly change the scroll speed over several frames. This is often changed. Call this scrollSpeed.
It seems I have two ways I can store and access these values and darned if I know which is better practice. METHOD A: Make them local variables in the class, so the scrolling background instance has them as local vars. I set them up thusly:
[Code]....
I am setting new style on a combobox instance. Following is the code.
myCombobox.textField.setStyle("textFormat", myStyle);myCombobox.dropdown.setRendererStyle("textFormat", myStyle); where myCombobox is the combobox instance and myStyle is textFormat object. but when i disable the component. i.e, myCombobox.enabled = false; The combobox textField loses its style and resets to its defualt style, though the dropdown style remains( myStyle ). What is the reasons for this behaviour. How can i change the style for the disabled state of the component.
I have a function that once called creates some new variables
function createPane(event:Event):void
{
var manager:IPaneManager = map.getPaneManager();
[code].....
I have a general / somewhat newbie question. Is it better practice to call a function from another class like so:
[Code]...
Does one way free up more memory or enhance performance?
I have to admit I pretty much ran away from Flash when AS2 came along and only used it for animation purposes over the last 5 years.So I'm having a major crash course in AS3 in Flash CS3 and I'm not enjoying it one bit. I'm getting maybe 10mins of finished work per hour as I try to figure out the limits and rules of AS3. Quite often it seems that AS3 simply can't do what I want it to. Anyway: Characterchecks.as is the main class and it loads a bunch of XML into four arrays. The file starts like this:[code]If I trace the value of, say, cc._Categories from the main FLA, it's empty. I'm guessing that the next line of AS in the main FLA doesn't wait for the previously called function to complete? (This may tie in to my next problem)My next step is that I want to display various things based on the data in the array. I have another class, Display.as which will hold all the functions to create the items on display. I thought it would be best for these to be a separate object. I wonder if I'm right?
So I declare an instance of Characterchecks in the main FLA and call it cc, and then run the functions to populate the arrays... Now I create an instance of Display and call it cd. How can I get functions in cd to see the values of the variables in cc? And if the main timeline can't tell that the functions aren't finished filling the arrays, how is cd supposed to know?I might be asking dumb questions, or maybe I'm doing things ***-backwards, I don't know. I'd appreciate any help, I really would. This whole thing has me at the end of my tether... being the most technically advanced person in my circle of co-workers and web design friends means I have no-one to explain why things need to be done a certain way or what the best way is.
I am wondering if it is possible to create a closure in ActionScript2 like it is possible in Javascript. This doesn't work:
[Code]....
var clearId:int = setTimeout(function():void{
//some code here
clearTimeout(clearId);
[code].....
I have a error TypeError: Error #1007: Instantiation attempted on a non-constructor but i can't figure out what i am doing wrong. I have a class that declares a static closure that instances the same class.
[Code]....
I need to detect browser/tab closure from within a flex application in order to delete the session information in the server. I'm familiar with JavaScript events but I was wandering if there is an event in flex for application unload or something of that sort ...
View 4 RepliesOn occasion, I have wanted to push a closure onto ActionScript's event stack so that it will be executed after the current event handler. Right now I use setTimeout(closure, 0). Is there a more direct way of doing this?
View 2 RepliesI seem to recall something about pass-by-reference and the Greensock TweenLite class. It's the only thing I can think of that is causing this bit of code to be not working as I intend:
for (var i = 0; i < 10; ++i) {
addItem();
}
public function addItem():MovieClip {
var item:MovieClip = getNewItem();
[Code]...
The trace is outputting the values I expect: an incremental sequence where each number is greater than the last (by the height of the item). However, what I see visually is that all the items end up at the same location (as if newPosY were the same for all instances of the tween.)
The only thing that comes to mind is that newPosY is being passed by reference, so each instance of the tween is actually referencing the very same value. Am I missing something? Or do I need some kind of closure to isolate the scope of my tween property's value?
I'm putting together a little application that has a simpe paint bucket functionality. I'm having a small problem, i'm sure it's an easy fix, but frankly I'm not much of a programmer.
Essentially what I have is a set of color swatches that users can select, and then a grid of movie clips with a series of frames, each corresponding to a swatch color. Over that, I have a grid of clear buttons that check to see which swatch is selected and then tell the movieclip underneath to go to the frame that corresponds to the right color. What I want to do is just set up the function once and call it for each movie clip, rather than repeating the function for each cell in my 6x7 grid.
[Code]...
I have a situation where, upon loading my swf, I add an event listener to the stage to listen for keyboard commands. One of them is to listen for the spacebar, and if it is pressed, it should play a movie. The problem is, that movie is not loaded until later on, depending other user interactions, therefore, until it is loaded, the reference to it would be undefined.
But if I wait and add the listener for key commands only when the movie is loaded, then I can't utilize the listener for other keyboard commands, like RIGHT or LEFT, which are the buttons which get you to the movie in the first place. Is there a way to add a conditional or something to prevent that code from being executed if the video is not defined yet? Here's my code:
[code]...
I'm using 9 textbox in my stage. Names are similar, only difference is the last character. (s1_0, s1_1, s1_2, ...). I'm trying to use these textbox in a loop. But I couldn't find the right typing... s1_[i], s1_(i) or s1_{i} gives error. s1_0.text=0 s1_1.text=0 s1_2.text=0 s1_3.text=0 s1_4.text=0 s1_5.text=0 s1_6.text=0 s1_7.text=0
View 3 RepliesI've been programming some stuff in Actionscript (haXe) and arrived this very specific problem. Here's the code (pseudo :S):
[Code]...
I am trying to add a LOAD EXTERNAL MOVIE CLIP behaviour to a button sitting in a .FLA called SERVICESMENU. I want to load a .swf titled MULTIMEDIA.SWF into an instance of an empty symbol called PAGE LOADER on a different .FLA called MAIN.FLA.
The problem is when I am in the SERVICEMENU.FLA file, I cannot see the instances that I created in the MAIN.FLA when following the behaviours wizard so I cannot choose the PAGELOADER instance that was created in and resides in the MAIN.FLA file.
It seems that my code is problematic, because I assign one instance of a MovieClip to several variables, type MovieClip. The behaviour of others of my codes makes me think, that ActionScript does not make copies of the instance, but references all variables to this single instance. This behaviour now causes trouble.The solution I consider now, is to create copies of the MovieClip and assign them to my variables. Is there any code to copy a MovieClip?
View 8 RepliesThere's a way to get the instance name of objects/symbols for variables and use this in actions and/or functions?
View 4 RepliesIm looking to have something along these lines, different variables that build the path to the object so that I can have it change dynamically.I'd like to have something like:
function foo(e:MouseEvent):void {
var1.var2.var3+_button.gotoAndPlay(2);
}
[code].....
So, I have something like..
Code:
select = ("block" + number);
trace(select._currentframe);
number++;
This is because I have 5 movieclips named block1, block2, etc. However, it returns undefined. When I directly state the instance name, like:
Code:
trace(block1._currentframe);
It works. How do I use variables as instance names?
if i have a movie clip in my Scene 1 and inside that movie clip is another symbol e.g. a button, how will i reference the instance name of that button in my Scene 1
View 2 RepliesI've read on the net that actionscripting from the action layer will result in a more readable file once published, as apposed to attaching onClipEvent functions which slow down readability.
For this reason I am trying to add variables to a MovieClip I have on the stage with an Instance Name of Player. However I wish to assign the MovieClip variables from the actions layer using the MovieClips Instance Name.
[Code].....
I have created movie clips using loops that names them box1, box2, box3.... via = i + 1;duplicateMovieClip (_root.box, "box" + i, i);but i then want to edit a textbox which is rooted inside each movie but related to the movieclip just produced. so if box1 had just been produced then:box1.textbox.text = " E cell = +j+"V";is done so effectively i am looking to do: box+i.textbox.text = " E cell = "+j+"V";
View 2 Replies