As3 :: Flash - Dynamically Name A Variable On An Object?
Feb 11, 2012
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"
I have an overlay that I pull up in response to a button click. This overlay is dynamically populated by a TextField, a MovieClip, and a Bitmap. I used to add them to the overlay with addChild() and induce a index out of bounds error to make them go away (I was in a hurry and I don't think I'm using removeChild() right). Well, I decided to do it better and dynamically change the object inside the holding variable. However... the Bitmap is gone. It won't appear. The overlay puller function takes a data-holding class I made and the picture is a BitmapData object.
I can't use the line new Bitmap(picture) because it doesn't work; that makes nothing appear. So, I guess my question is can I store a line of text in a variable and then use that variable as code? Like... Could I have something like this and get an image as an output? I imagine it could be done with XML, but is there another way? I tried storing the constructor in a variable and calling it with object.constructor, but I don't know if I was using it right and it didn't work.
I have a case where I have a "drop-down box" in an HTML webpage with some JQuery calculations, looks something like this:[code]What I'm trying to do is have this Flash ActionScript 3 Application (embedded on the same HTML page) grab a variable from the drop-down box. Now, using FlashVars is fine, except it doesn't account for when the selection is changed (obviously), but..Is there a way to reload the variable into Flash real-time when the user changes the drop-down box selection?
I want to change the value of a variable which is inside another flash movie .I have loaded the swf file.Inside the 'onLoadInit' function i wrote the code like below.
I have an HTML button that I need to dynamically assign to an AS3 variable when clicked (in order to load an .mp3). I am using externalInterface.call to collect javascript variables - I am just unsure how to change these dynamically when a button is clicked.
I have 14 buttons, and each one declares a variable; example:
[code]...
On the next frame I have another 14 buttons, and on Release I want to create a new variable with the content of _root.competencia; example:
[code]...
Instead Flash tells me this: Left side of assignment operator must be variable or property.Its what Im trying to do possible? Hope somebody can help me, has been 2 days, and I cant understand what is going on, I have tried a lot of ways without positive results, I know I have a long way to go to learn actionscript, Im to new in this!
I have a weird problem with Safari 5.0 and Flash player 10.1. When I resize the flash html object via ExternalInterface and JavaScript flash will jump down the page a little bit for a fraction of a second. Here is an example: [URL]. This may not be a flash question at all. It may be a CSS or JavaScript problem. It seems to only be a problem with Safari 5 and Flash 10.1.
You can view the source of the html page. Here is the code inside the sample FLA: one.addEventListener(MouseEvent.CLICK, oneClick); one.buttonMode = true; two.addEventListener(MouseEvent.CLICK, twoClick); two.buttonMode = true; this.addEventListener(Event.ADDED_TO_STAGE, addedToStage); [Code] .....
I have a Flash/Flex object (Flashlight-VNC), which I would like to dynamically resize to fit the entire window after pressing a button in the Flex app. This would preferably happen without restarting the Flex app (and therefore the VNC session). I would just use the built-in Flash fullscreen mode, however Adobe's somewhat silly security restrictions prevent keyboard input while in fullscreen mode.
How exactly can I do this? I'm already using SWFObject to embed the SWF, if that helps. I am open to any solution utilizing ActionScript, JavaScript, or both, however I am not all too familiar with ActionScript or Flex, and the AS-based solutions I have found involve extending a "Sprite" object to add resize functionality, which Flashlight-VNC does not seem to use.
I have a legacy file format that contains sounds embedded in it (in various encodings). I would like to be able to play these sounds in Flash (Air?) by reading the sound bytes out of the file and instantiating a Sound object with them.
If the sound is unencoded (e.g., raw pcm), I've found that I can use the new flex 4 SampleDataEvent.SAMPLE_DATA event to play the sound.
However, if the sound is encoded (e.g., mp3), then I'm at a loss. The sound expected by SampleDataEvent.SAMPLE_DATA has to be raw pcm. From what I've seen, encoded Sounds can only be instantiated by [Embed]ing them, or by using a URLRequest with Sound.load().
I'm made an Item class which extends the Sprite class, the Item class basically has a few checkmarks & labels at the moment.
Then what I try to do is run through a for loop of items and create Item classes that I want to place one after each other on the y-axis, so I'm reading the Item.height property to find the y of the next Item in the list.
The problem is for some reason there is always an extra 75 pixels added to the Sprite height at the bottom, no matter how many checkmarks and labels are in each Item class ( varying the height of the Item class ).
Any idea why this is being added and how it can be removed?I'm having trouble figuring this out, I tried dynamicly calculating and setting the Item.height property but when I do that the Sprite is simply cropped.
I'm trying to dynamically addChild a Sprite to an already tweened MovieClip (tweened on the Flash timeline). Let's say ObjectA is the tweened object, I published it in my swc and linked it to my Actionscript project in Flash Builder. I make an instance of ObjectA in my class, and then try to do the following:
var objectA:ObjectA = new ObjectA(); var objectB:ObjectB = new ObjectB(); objectA.addChild(objectB); addChild(objectA);
Now, the problem is, objectB doesn't tween along with objectA. Is there any logical solution to this?
URL...An untyped variable is not the same as a variable of type Object. The key difference is that untyped variables can hold the special value undefined , while a variable of type Object cannot hold that value.[code]Why is assignment to undefined allowed for obj? (not a big issue since it still prints as null)If we compare null with undefined the result true (even if null stored in an Object). What is the point of making a difference between null and undefined if they are equal?
I'm relatively new to Flash and ActionScript and have a problem with the following code I'm putting together:
Code: // creating a new testmclip object var testmclip = new testmclip(); // creating a new testmclip object /* create a new pop up menu - sending the testmclip as var and "test" as label */ popupmenu = new Menu ([path: testmclip, label: "test"]);
I'm trying to send a movieclip object created in one class, to a different class - for the latter class to add as it's child. The code was originally Kevin Hoyts Android Component for Menu and MenuItem [URL] ... but in that the path for the menuitem was a path which loaded from url or relative path --> this I can't do with flash...I think.
I'm attempting to make a platform game. Each level is contained within it's own MovieClip, which has it's own class. Each of these classes extend the Level class, which provides basic functionality for all levels.
Each individual level has a numPlatforms variable which stores the number of platforms in that particular level. I currently have a for loop that runs from 1-numPlatforms and sets the level area (the image, more or less) the platform contains:
[Code]....
Is there any way to check if a variable exists within a MoveClip? I've trying comparing it to null and also to undefined, but neither works.
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.
How to add a child to the stage dynamically? I can get a child to add to the stage but not using dynamic variables. Is it possible? Example: var firstRoundWinner:String = "Redsquare"; var mc:MovieClip = new firstRoundWinner(); // want it to say = new RedsquareaddChild(mc); With Redsquare as one of my movieclips and the linkage is working. I can add it if I hard code it. But I want to load the variable dynamically through xml.