I'm fairly new to AS3. In AS2 I often used objects to store properties so I can creatre them dynamically and refer to them later.Sometime I use an array as a property. I am wondering if my method of doing this is the best way, or if AS3 has other methods that might be better suited.In this case I have an object that stores properties like ID no. and I also want to store an array of sub properties which are in array.[code]
i'm attempting to cast an object's property as an actual property of another object. here's my object variable: var propObj:Object = {prop:"width", width:50}; now i want to assign the property of a sprite using that object's properties. var sp:Sprite = new Sprite(); sp.(propObj.prop as Sprite.property) = propObj.width; now, i'm not even going to try that because i know the compiler will explode all up in my face. but you should be able to see what i'm trying to do. why i'm trying to do it is because i'm reading in an XML file with an undetermined list of usable properties for specific objects. so instead of writing something like a huge switch statement to evaluate whether the XML file has a value for that specific property, i'm trying to assign properties dynamically based on what's available in the XML file. if what i'm trying to do is possible, what's the best way to do it?
I forgot to put it in the title so I'll just place it here; I am using AS 2.0. I know that there are other ways to accomplish the goal that am after, but I was wondering if anyone knows of a way to access the properties of an object's properties?
Here is the code that I thought of, even though it doesn't work
var a:Object = new Object(); a.bproperty = 0; //lowerlevel properties a.cproperty = 1; // lowerlevel properties
[Code].....
This really just boils down to how I am organizing the code(I have ideas on what do next, and i am 99% sure that I can get them to work), and if there is a way to dynamically access the properties of the objects properties, It will save me from creating yet another large block of code for my project. If you want to see the unfinished project, go to [URL]
Allright, i receive a string and want to convert it to object. here a test that i have made:
[code]....
this work pretty fine... but i am receiving the object property as follow: "{a:'test',b:'testAgain'}" How can i easily convert it to object properties?
I've exhausted searches looking for how to add properties to the component properties panel for a custom AS2 and AS3 components.This Adobe Livedoc suggests using Inspectable tags before variables:[URL]I've also tried adding the components via the Component Definition dialog in the library.Both methods work in that they produce an .swc, but neither adds the properties into the Component Properties.
I'm basically loading an XML file to assign instances of a movie clip a distinct value, which it uses to modify its height. So, I'm looping through the xml and instantiating my class Object each time (Rect) and then placing that Object into an array:
Code: function loadXML(loaded){ if(loaded){ var boxArray:Array; xmlNode = this.firstChild;
[code]....
the trace here always comes up undefined. "listPosition" in this bit is an Rect parameter, defined in the previous bit of code as "i", so I can keep track of the order of the stack.I've found one or two examples of putting objects into an array and getting them back out, but it doesn't seem to work with this, maybe because I'm using a class. I don't know.Could this be an area where I need to use the array access brackets, like around the movie clip the object is loaded into. I've tried everything I can think of -- referencing back to the movieclip, adding extra objectRef type parameters... nothing has worked yet.
i'm currently using a dictionary to associate a boolean to my (non-dynamic) sprites, but i would like to know if there is a smarter way of doing this? i could just use MovieClips to assign my properties instead of Sprites since MovieClips are dynamic, but i will not be using any of the MovieClip properties or functions so it comes down to a best practice issue. basically i want to create a state boolean property on my sprites - they are either on or off so my boolean variable is called isOn.
I tried rewriting Senocular's AlignmentProperties that alter the prototype of a MovieClip for AS1 and AS2 in AS3... (Basically it adds a top, left, bottom, right, centerY, centerX property to all MovieClips so you can align them regardless of their registration point)Now, I know you (senocular) say prototypes are not typically used anymore for AS3 but they are still there in case you need them. I think this utility could be pretty useful. What are your thoughts on how a property could be dynamically added to a class in AS3?[URL]trace(my_mc.top);// traces the top of a movie clip regardless of the registrationmy_mc.top=0; //aligns the top of a movieclip to 0 regardless of the registrationBut ran into a snag adding properties to a class via prototype.Here is my class...
I have done this same thing in ActionScript 3, but am not familiar with ActionScript 2, which I am forced to use for this project. I am loading products into a SWF via XML and attempting to add a click event to each dynamically-created movieclip. Simply tracing the text from a node in XML will do for now. I'd like to assign a property called "desc" or "description" to each movieclip and have it trace that property's value when clicked. Here is the relevant portion of my code as it stands:
I'm doing some work with JSON in as3 using as3corelib (very useful) and was wondering if it is possible to get an object if all you have is one of its properties, also an object. Here's an example of some JSON:
"parentObject": { "propertyObject": { etc. } } so what i'm asking is, if I have propertyObject, can I access parentObject somehow?
Back in the day (AS2), I used to create what I called an"ivar" property that collected the index of a series of buttonsthat were clickable (see attached code). Imagine 10 buttons on thestage with names (selectButton0, selectButton1, ...selectButton9).The code under the //----------BUTTONS header would make a propertyof the button that was clicked, call it "ivar" and then send it upto a function that would use it as an index to then load theappropriate content with MovieClipLoader (remember that Class?).I have tried something similar in AS3 without any luck sincethe whole button thing is now steered by events. Does anybody knowan elegant solution that would achieve a similar result. That is,click a button called "selectButton0" and have returned the zero asan index variable that could be used further?
ActionScript Code: public static var places:Object = new Object(); places["MyHouse"] = ["My House", new Point(PointX,PointY)] places["YourHouse"] = ["Your House", new Point(PointX,PointY)]
I am having a hard time understanding for...in loops. I have seen David use it in his signature, and I understand what the loops is doing, but only from the context of the rest of the signature. If somebody could explain how the for..in loop works, I'd be greatful. Here's what I know:
PHP Code:
for (proprtyThing in objectThing) { trace (proprtyThing); }
My understanding of this loop tells me that if I run it, I'll get a list of all the properties of the object named objectThing....but this makes no sense to me!!
I'm working on a project that has to pass variables to (and later read them from) a URL encoded text file.
Code: getURL("process.cgi", "", "POST");
This has worked until now, dumping all of _level0's variables into the document, retrieving the relevant ones on load.I've recently made some modifications so that I'm no longer storing all the variables in _level0, but some of them as custom properties of objects, e.g.:
I have done this same thing in ActionScript 3, but am not familiar with ActionScript 2, which I am forced to use for this project. I am loading products into a SWF via XML and attempting to add a click event to each dynamically-created movieclip. Simply tracing the text from a node in XML will do for now. I'd like to assign a property called "desc" or "description" to each movieclip and have it trace that property's value when clicked. Here is the relevant portion of my code as it stands:
ActionScript Code: var iXML:XML = new XML(); iXML.ignoreWhite = true;
For the first stage, I was able to build a walk-through demo in flash pro by creating buttons that when clicked caused the flash to change to different frames. easy enough. Now for the final part of this project, I need to make the interface fully interactive, as I was trying before. ie: you can click any button and lights go on and off or a loop counter increments, etc. Since there is logic involved and too many permutations to do a frame for each possible state, I'm back to trying to do this in an object oriented way. I've got some test code here.
<fx:Script> <![CDATA[ protected function button1_clickHandler(event:MouseEvent):void {
[code]....
debugger has some errors, so i don't know what exactly it will do. the errors are at the last two if statements where i'm trying to change the object property setting of the label. there is another error at the last curly bracket.
the idea is that there are two labels and a button. the first label starts out visible. when the button is clicked, a counter is checked, and incremented, then the counter is again checked and the appropriate label has it's visible property set to true. the intent is that in a list of several labels, pressing the button scrolls down them, until you press while on the last, which resets the counter and the first label becomes the visible one.
I'm just starting to learn about classes in actionscript, I am following along with Moocks book Actionscript for Flash MX and are trying to execute a trace on the properties of my ballclass but all I get is undefined. He is what I have in my actions panel.[code]
I want to set it up so the size properies will pass over to the block (same object size - height and scale) but also changing the collision properies so the player will be enable push the block around the screen but I'm not sure how to implement such functionality/feature. I've experimented with two ways so far; 1.) The enemy changes to a frame of a block when he dies (illusion of a different object but the same object with a different frame on the timeline) using the same size properies but I can't seem to the change the collision properies from it's prior setting of causing damage and re-bound/bounce to the player. 2.) The enemy is removed completely from the game and a new block object is added in the same position where enemy died but I can't share/code the same size properies to this new block object making obvious that is a different object. Here is a code I've what I've done so far (which is attempting to do first approach);
In actionscript an object's property can be accesses in this way: object["propertyname"] Is something like this possible in c#, without using reflection?
In order to send a POST request I need to enumerate all properties of a given object. This object may or may not be dynamic. I'm looking for the most elegant solution. This is what I've got so far:
I have an engine I created a while back that loads objects into a container based on XML data. A really quick example of the XML would be like this: <level> <object cname="enemies.Robot"> <pos x="200" y="400" layer="mobiles" /> </object><object cname="Player"> <pos x="12" y="89" layer="mobiles" /> </object></level>
I have a class Environment that has a method loadLevel(data:XML) which I parse the XML through, then the function runs through the XML finding all object nodes and uses getDefinitionByName to determine which Object I want to create based on object.@cname. From here, I have to manually define each property based on the XML like so: obj.x = xml.pos.@x; obj.y = xml.pos.@y; etc.
I was wondering if there's an inbuilt method for setting a property based on a String. By this I mean something like so: var mc:MovieClip = new MovieClip(); mc.someInbuiltFunctionThatSetsAProperty("alpha", 0.5);
This way I could change my XML to be more like so: <object cname="Player"> <props> <x>200</x> <y>221</y> <alpha>7834</alpha> <health>Something</health> <power>3</power> </props></object>
And iterate through all the children of props to set all of my properties on the fly. I know if I create an Object and set properties within it like so: var obj:Object = { var1: "hello", var2: "there", name: "marty" };
That you can then iterate through names/values using the for(String in Object) loop like this: var i:String; for(i in obj){ trace(i + ": " + obj[i]); } /** * Output: * var1: hello * var2: there * name: marty */
Surely there's a way, as here's an example of identifying a property using a String: var ar:Array = [new MovieClip(), new MovieClip()]; ar.sortOn("alpha", Array.ASCENDING); So just to make my question more to-the-point: I want to be able to get and set properties that I can identify using a String.
I'm doing some Actionscript work right now and I'd like to know whether there's a way to initiate an empty object's value programatically like this:
var myObj:Object = new Object; myObj.add("aKey","aValue");
To add a property called aKey whose value is aValue.I need to create a "Dumb" (data-only) object to use as a parameter to send via POST. So I don't know offhand how long and/or how many attributes it's gonna have.