ActionScript 3.0 :: Use Variables For Instance Name?
May 30, 2010
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 Replies
Similar Posts:
Mar 14, 2006
I 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]....
View 4 Replies
May 28, 2010
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 Replies
Jul 23, 2009
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 Replies
Jul 13, 2007
There's a way to get the instance name of objects/symbols for variables and use this in actions and/or functions?
View 4 Replies
Mar 9, 2010
Im 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].....
View 1 Replies
Nov 11, 2010
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?
View 2 Replies
Sep 11, 2009
I'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].....
View 5 Replies
Jun 20, 2006
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
Jul 24, 2007
I 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 Replies
Oct 18, 2007
I am using the tween class to change the alpha value of a MC upon rollOver and rollOut. To refine the effect, I assigned a variable to the MC's alpha value so if the mouse moves off the MC before it has reached 100% alpha, it wont start immediatly fading from 100%, but from the value it had reached before the user stopped the rollOver action. Unfortunately, when I leave my mouse over the MC until it goes to 100%, and then I wait a second or two, the alpha snaps back to 50% (the starting alpha value).I can't figure out why this keeps happening, but I have run into it with other projects and I surmise it is the way I am using the tween class. Below is the code I used to make this happen.To see the problem, here is a link to the compiled file:
// image 1 Set 2
groupA.group2.image1.onRelease = function() {
loadMovie("main_resized/1.jpg", pictureHolder);
[code]......
View 1 Replies
Jul 3, 2009
In the following code I would like to be able to change which object the code affects depending on which parameter name is passed to it:
Code:
EventCentral.getInstance().addEventListener(ProjectEvent.SOME_EVENT, handleSomeEvent);
function handleSomeEvent($event:ProjectEvent):void
[Code].....
I could write it all out with ifs and else ifs for each parameter but this code is already part of quite a large structure and it would be more elegant to be able to do it with re-usable code.
I'm trying to do it is particularly idiomatic to actionscript anyway
View 1 Replies
Jul 21, 2009
I have two classes a main and one controlling a cloud graphic going on the stage. In the main class I am creating an instance of the cloud, adding it to the stage with an array and with a for loop I am setting the x speed (vx). I have noticed that if I set the vx in the cloud class and reference it directly then it does not work (clouds are drawn for a millisecond then a blank movie). I have to initialize the cloud.vx value in the main class to get it to work. Why can I not just pull the vx value from the cloud class without setting it to a value in the main class?
Main class
Code:
package
{
import flash.display.MovieClip;
[Code].....
View 14 Replies
Nov 21, 2010
So, I have:
function respawn(enemyid){
clearInterval(respawnTimer);
enemyname = "enemy" + enemyid;
[code]......
View 5 Replies
Oct 8, 2008
I can get the variable into Pages.as now but the Loader will not "reload" hen the button is clicked.
View 35 Replies
May 17, 2009
- I tried, when I first started making this site, to load all of the artwork images into an array and then copy the array before resizing them for their specific functions (being seen as thumbnails or as full size pics.) Unfortunately, I ran into the well known issue of Array cloning only creating a pointer to the same group of items. I tried the newArray = oldArray.slice() trick, but it didn't seem to work. Finally, I just loaded the images twice into two separate arrays, and it works, but I hate this solution. Anyone got a better one?
- I'm trying to maintain some sort of connection between the two sets of Arrays so that, for example, when someone clicks on Thumbnail 15, Fullsize Image 15 will open up but I couldn't find anything that worked. Renaming the Instance Name dynamically didn't seem to work and adding an Instance Variable dynamically doesn't seem possible either as I can't make the Class I am working with (Sprite, in this case) dynamic ahead of time. I'm sure there's a simple method for this.opens up, the different animations seem to interfere with each other and slow each other down (they also seem to get interference from the time taken to load the image Arrays.)
View 9 Replies
Aug 18, 2010
Currently I have two classes which are "bullet" and "enemy".There are two instances of the enemy class.Code from an ENTER_FRAME event in the Bullet Class:
ActionScript Code:
try
{
for(var k:int=0; k<getEnemys.length; k++)
[code]....
The Enemy Class has a private variable called "hits".What do I have to do in order to reduce the hits of the instance of the enemy that was hit by the bullet?
View 5 Replies
Jan 28, 2010
I know what instance variables, contractor methods, local variables and constructor arguments are (I think) but I'm confused as to when or how to use them, for instance I have use this a lot and I don't really understand why it is used like this...
[AS] package standard.testing {
import flash.display.MovieClip;
import flash.events.Event;
import com.greensock.*;
[code]....
Why create a function with arguments...
[AS]public function tweenMe(mc:MovieClip, xPos:Number, yPos:Number)[/AS]
Then create instance variables...
[AS]
public var _mc = MovieClip;
public var _xPos= Number;
public var _yPos = Number
[/AS]
then create local variables with the values of the arguments
[AS]
_mc = mc;
_yPos = yPos;
_xPos = xPos;[/AS]
View 6 Replies
Jan 26, 2006
I'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().
View 5 Replies
Feb 10, 2012
How can I access instance variables in closure(inner function) for this style: this['varName']?
[Code]...
View 1 Replies
May 11, 2010
I narrowed the causes of an AS3 compiler error 1119 down to code that looks similar to this:
var test_inst:Number = 2.953;
trace(test_inst);
trace(test_inst.constructor);
I get the error "1119: Access of possibly undefined property constructor through a reference with static type Number." Now if I omit the variable's type, I don't get that error:
[Code]...
So what's the deal? I like explicitly typing variables, so is there any way to solve this error other than not providing the variable's type?
View 3 Replies
Mar 20, 2009
Does creating a new instance of an Object that uses an identical name to an older instance, delete the previous instance? Or should the original instance be deleted first? The code uses a ridiculous amount of XML vars. Isn't it less memory intensive to parse the XML and save the properties to an Object, and then delete the XML Object, rather than keep the XML Object around and reference it's child nodes directly? Is it better form to break up a huge XML file (>600lines/3200vars) into smaller chunks?
View 1 Replies
Jun 17, 2010
I have a library object (SomethingMC) which extends a custom class (Something). Something, in turn, extends MovieClip.If adding SomethingMC to the stage within Flash CS3 IDE, is it possible for it's super class (Something) to assign an instance name from a class constant (Something.THE_CONSTANT)?
package
{
import flash.display.MovieClip;[code].....
The above does not work. It throws Error #2078: The name property of a Timeline-placed object cannot be modified. if the instance is assigned a name in the IDE, and it just doesn't work if no name is assigned in the IDE.
View 1 Replies
Dec 2, 2010
I have a BUNCH of bumpers of four types bounceUp, bounceDown, bounceLeft, bounceRight. during a collision which you hit determines the bounce so they always do the same thing so here's my question.....can i just name every bounceUp instance the same thing and then just add that one instance name to the list the collision detector checks?
i just dont wanna go through and name a hundred each of bounceUp s and bounceDown s individually as the potential for screaming increases proportionally.......
View 5 Replies
Apr 16, 2011
I placed a movie clip instance inside a button, and I want this movie clip to play when the button is released. I'm using this code on the frame containing the button:
function playMovie(event:MouseEvent)
{
this.theButton.theMC.gotoAndPlay(3);
[code].....
View 2 Replies
Jul 19, 2004
Does anyone know if it is possinle to scroll a graphic or a movie instance as well as a text instance in flash. I want to scroll text and images as well. Actually text with imges embedded in it.
View 3 Replies
Jan 26, 2009
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?
View 5 Replies
Feb 12, 2012
I have a base class I've used on 6 different MC's. Then when I use these MC's my function runs an if statement to check which one to add.
if(id=design) var obj = new design();
if(id=team) var obj = new team();
I want to make it a bit more dynamic and use the id:String to evaluate which new instance to create.
ActionScript Code:
public function loadChapter(id:String):void {
var obj = new instance_of( id )();
}
View 5 Replies
Jan 28, 2010
I have a bunch of text boxes which are acting as labels on a diagram.The idea is all the labels are jumbled up to start with, and the user has to drag the labels to the correct place.So far, I have the labels, and they are dragable, but I want to be able to lock the label onto a specific area (I've called them crashzones) so that when the user drags the label onto the correct area, the label snaps into place.The 'crashzones' instance names, are indentical to the label instance names, with the exception that the 'crashzones' instance names have the letter 'z' at the begining.
On the dragStart event, something (maybe a string) would hold the instance name of the current label and add the letter 'z' to the beggining, so something like ... crashzone = "z" + label1;As there is an instance with the name "zlabel1", when the dragstop event starts, it'll do a 'hittestobject' on the instance "zlabel1".
I'm not entirely sure how to go about this.I've tried creating a string to hold the 'crashzone' name, but the hittestobject event doesnt work with strings i.e: hitTestObject(stringname);I've also tried with Sprite, but as the sprite technically already exists and has a name, I can't give the sprite any properties.
View 1 Replies
Jan 22, 2010
I have a base class which is being created via remote_object [RemoteClass alias] from the server.I have other specialized classes that are derived from this baseclass, but serialization with the server always happens with the base class.The base class has meta data that defines what the derived class is, for example
[RemoteClass (alias="com.myco...')]
public Class Base
{
[code]....
View 2 Replies