I have some variables in the format: var like6Y:Number = 50; Later I am dynamically setting some: num=6; Then I am trying to use that num to get the variable like6Y: like+6+Y I know that is totally wrong but I seem to remember you could use some kind of object notation to accomplish this: ["like"+num+"Y"] Or something along those lines. But I can't remember how to do it.
I've created a custom class to represent a monster in a game. The class definition has "public class Monster extends Object". I'd like to know if there's a way to initialize the object using object literal notation. For example, this works ok:
[Code]...
I get this error: "Implicit coercion of a value with static type Object to a possibly unrelated type Monster." Is there a way to do this? I'd rather NOT have to call the Monster's class initializer each time, because in the actual code there are a lot more variables in the monster class than just those three, and it's kinda unwieldy to pass a dozen long strings into the new() function.
I just started an open source project @ Google Code. I came up with this simple notation for a recent project. I have since used it on several projects and am happy to share it with anyone else who might benefit. I could also use a hand with the documentation and also features if anyone is interested in helping out. Take a look and feel free to provide feedback. [URL]
In the following example the first trace gives me the xml data at the node, but the second trace does not. This is AS3. How would I use a variable to do the same as inline dot notation?
var x:String = "animXML.home.version"; trace(animXML.home.version); // this works trace([x]); // this does not
I have the following: ActionScript Code: if ((player.charVelocity < 9.0180945396304027e-26 && player.charVelocity > -9.0180945396304027e-26)) it seems to be firing as soon as charVelocity gets between 1 and -1. Am I writing that correctly? I assume it would work as I copied the syntax it was outputting for the variable value (which is set to 'int')
I am trying to create a number of movie clips in my main movie but I don't seem to be able to access these movies using array notation and the 'this' keyword. Here's some example code in a main timeline. var i=0; createEmptyMovieClip("clip"+1,0); trace(this["clip"+i]); ////undefined - why????? var clip=createEmptyMovieClip("clip_holder",1); clip.createEmptyMovieClip("clip"+i,0); trace(clip_holder["clip"+i]); /////_level0.clip_holder.clip0. This is ok. What's wrong with this["clip"+i] ?
I have 10 or 100 or 1000 mc's on stage that do exactly the same on an onRollOver event and on an onRollOut event, what's the easiest way of writing this ? let's assume that the mc's are called mc1 to mc100, could it be done with an array and/or for statement ? Cause I'm used to old fashioned coding, I'm used not to try to cut corners So it kind of restricts my thinking a bit at times. So, do I need to start with an onRollOver event handler for each button in order to make Flash notice the onRollOver event for each button ?
I know that a dynamic mc can be referenced using array notation viz: myArray['someName'+i] My question is ... can mcs that have been placed on the stage and given instance names be referenced in some similar way? If I have placed 10 mc's with different instance names eg mg1, mg2, mg3 etc, can I reference them using array referencing?
I've got a calculator that i created in as2 that converts different units of measurement. However, right now it always converts the numbers into a decimal number like 0.33333333 or 450.72. How in the world would i convert these decimal numbers to scientific notation? For example, say i have a number: 12,700. Expressed in scientific notation, this would be 1.27x10^4.I hope there is an easy way to make flash convert to such a number system? I know its easy to round numbers in decimal, but have never worked with scientific notation before.
How can I create an xml object (or any object in fact) named after a variable, i.e variable called section with value "names" create object [section value + "XML"] = new xml(); result: empty xml object called namesXML
I have 2 classes, Display holds the currently selected Component:
public class Display { public static var selectedComponent:Component; }
Component has an ID string and the selectedComponent variable is set on click:
public class Component extends MovieClip { public var id:String; addEventListener(MouseEvent.CLICK, function() {
[Code]...
Removing the selectedComponent variable type so it reads public static var selectedComponent; removes the conversion error and seems to change the ID variable but it appears to only be a copy of the object.
i'm building a band website in joomla. Each band has it's own page. I want one mp3 player to cover al bandpages by just editing the url of the playlist.xml (the variable)
I want to connect the pageid (itemid as it is called in joomla) to the xml.
I have attached a simple test fla.I am trying to centralize my code in all my movies using dot notation instead of spreading my code all over the place. It never works, I must be doing something wrong.The test .fla has a movieclip with a timeline animation. I used the linkage identifier to name it 'reload' AND named the instance 'reload'.
Is there any reason why Vector would not be supported in CS3?
I have the following line: private var pageRequests:Vector.<PageRequest>;
I'm getting a compiler error on the "." but that seems to be the defacto Vector notation. If for some reason this isn't currently supported in my version of CS3, then does anyone know how I can update the actionscript library to allow it?
There is something I couldn't solve: when I search a specific node in a XMLList containing several level of hierarchy, filter never search in the top parent node. For example, if I have a tree like this:
I have a class Inhabitant with a property skin which is of type DisplayObject.
Within Inhabitant I need to access the x and y properties of skin using this method:
this["someProperty"]; Rather than: this.someProperty;
This is fine with properties defined within Inhabitant but I'm not sure how I could do this for a property of skin. This obviously doesn't work but it might give you an idea of what I'm trying to do:
this["skin.x"];
The reason behind requiring this notation is that I have a function which I can parse a String though that will represent a property:
public function addTokenable(property:String):void { if(!isTokenable(property)) _tokenables[property] = true; }
And then a related getter that will return a representation of this instance of Inhabitant as a String:
public function get token():String { _token = "class:" + getQualifiedClassName(this).split("::").join(".");
So, if I need to give a custom variable name to an object how would I do that?
For instance, if I have a gameID that is 12345 and its rating is 3 I want to save a variable called gameRatings_12345 thats value is 3 in my shared local object.
//share object protected var mySavedData:SharedObject = SharedObject.getLocal("mySavedData");
I have the game id in a string
var gameID:String = "12345";
Then when I try to assign the value like this...
mySavedData.data.gameRatings_gameID = 3
I think it's literally reading it as "mySavedData.data.gameRatings_gameID" instead of "mySavedData.data.gameRatings_12345"
How do I relate a variable to an object on the stage? I want to have a mouse over and a mouse out effect on a button yet when I use the code below I get the error:
ReferenceError: Error #1065: Variable button is not defined.
obviously the object on the stage is called 'button' but I didnt think I had to define objects as variables? I thought the below code was correct?[code]....
So ive made a custom message system for my game and the scrollpane component requires me to have the info inside one movieclip. I have a couple of textfields there that i want to change to some variables on demand. The vars are in an external as file and im able to reference them well on the main timeline. The problem is when im inside the scrollable object, all the vars return blank instead. This is the code which is placed inside the object:
Code: import Variables; var variables:Variables = new Variables(); function setMsgSlot (e:Event) {
I'm wanting to set an Object property using a variable value. I just can't get it to work as it assumes the variable name is the name of the property: I've simplified the issue rather than posting my whole code.[code]It always applies 'attrName' as the property name rather than the value of 'attrName'.Tried loads of things but just can't get it to work.
I am in no way very knowledgable with ActionScript, so this might be very simple and I am looking in all of the wrong places... but basically here is my issue: Instead of accessing an objects attributes like this, _level0.thumbnails.thumbnail0._width = 500; I want to be able to access it with _level0.thumbnails. (this.id) ._width = 500; where as (this.id) is a variable that could be equal to "thumbnail0" or "thumbnail99" depending on which object gets clicked. I have everything working to if I hardcode thumbnail0 it works fine, and this.id does get set to whatever thumbnail I click's "thumbnail" + ID