C# :: - Accessing Object Properties From String Representations

Mar 19, 2010

In actionscript an object's property can be accesses in this way: object["propertyname"] Is something like this possible in c#, without using reflection?

View 2 Replies


Similar Posts:


ActionScript 3 :: Accessing Properties Via String In Object

May 1, 2011

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.

View 2 Replies

ActionScript 3.0 :: Accessing An Object Through One Of Its Properties?

Jul 7, 2011

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?

View 2 Replies

IDE :: Accessing Object Properties On A New Frame?

Apr 25, 2009

I'm having trouble accessing objects on new frames.On frame 1 I have:

Code:
var HelloWorld:Object = new Object()
On frame 2 I have:

[code]....

View 3 Replies

ActionScript 2.0 :: String To Object - Easily Convert It To Object Properties?

May 17, 2005

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?

View 4 Replies

ActionScript 2.0 :: Accessing Object Properties Dynamically?

Jun 21, 2007

I have a custom property called Player (like a basketball player) that has properties for points per game (ppg), rebounds per game (rpg), etc.I'm designing a piece where users can get averages and compare players across many different categories.

I have a String variable "stat" that tracks which property they want to compare. I can use "stat" in a sorton function, but need to use it to access the object property. So when the user chooses "ppg" or "rpg" i can access Player.ppg and Player.rpg by using the stat variable. Player.stat doesn't work.

View 2 Replies

ActionScript 3.0 :: Accessing Object Properties Dynamically?

Jun 27, 2010

hat is the correct way to access an object dynamically? I have tried this with no success:

Code:
i += 1;
var myVar = this[myObject. + "myProperty" + i];

[code].....

View 3 Replies

ActionScript 3.0 :: Accessing An Array Inside An Object With A String?

Feb 2, 2010

I have an object with an Array of objects inside. Each object has a name property. To scope it directly I would use:

ActionScript Code:
obj._arrayOfObjects[0]._object name; // trace returns the first object's name in the array
if you understand this so far then here is an easy question for you.

[code].....

View 2 Replies

ActionScript 2.0 :: Initialize The Object With A String Variable Which Holds The Initialization Properties (without Parsing The Text)

Dec 5, 2005

I initialize the "point" object like:

point = {x:'209', y:'270'};
trace(point.x);

this is working fine, But I have to initialize the "point" object with a string variable which holds the initialization properties like:

[Code]...

I know this is not working. Is there any method to initialize the object with a string variable which holds the initialization properties (without parsing the text) ?

View 7 Replies

ActionScript :: Xml - Setting Object Properties From Other Object Properties?

Jun 25, 2010

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?

View 1 Replies

ActionScript 2.0 :: Graphical Representations Of Physics/mathematicsformulas?

Dec 12, 2004

Im trying to find some examples of graphical representations of physics/mathematicsformulas. You know, where a pattern is drawn based on that formula.

View 3 Replies

ActionScript 2.0 :: Trace The Properties Of An Object's Properties?

Jan 30, 2008

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]

View 3 Replies

ActionScript 3.0 :: Accessing Properties From Another Package

Oct 23, 2011

I am working on setting up some simple AI actions for my enemy class in the game that I am working on, but I am having trouble accessing the player's X location within the enemy package to set up a detection function. I have defined the player on my Level package along with the enemy, and I defined the player's and enemies X and Y locations within the Player/Enemies package respectively.

Within my flash file I have linked to my Level.as file. Also within my flash file library I have two movie clips. Both have a square in them that are the same size but colored differently. One is called PlayerSpriteMC and the other is called EnemiesSpriteMC.

[Code]...

View 1 Replies

ActionScript 3.0 :: Accessing Another Class's Properties From A Different One?

Jul 1, 2009

I have two movie clips on the stage at frame 1 and frame 2. Both are instances of seperate classes. (They are not dynamically created, just their linkage is set to their class names)I have created soundChannel and Sound Objects in Class 1 and I want to access them from Class 2. (I want to stop the sound channel that was started in class 1)Is there any way to do this? If yes, will this be true for other properties also?

View 7 Replies

ActionScript 3.0 :: Accessing Parent Through One Of Its Properties?

Jul 6, 2011

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:

ActionScript Code:
"parentObject": {
"propertyObject": {

[code].......

View 2 Replies

ActionScript 3.0 :: Accessing Methods And Properties Via GetChildByName

Dec 2, 2007

I seem to be having a bit of a problem here. I'm generating a load of class instances using the following code:

maxpersons=25;
for (var i:Number=1;i<=maxpersons;i++)
{
var person:Person = new Person;

[Code].....

OK. I then need to run through each of them and check for a collision with an object from the main stage (called redDot), which I pass to a method (called doDamage) within the class. I'm using the following code:

for (i=1;i<=maxpersons;i++)
{
if (game.getChildByName("person"+i).hitTestObject(red Dot))
{
game.getChildByName("person"+i).doDamage(redDot);
}
}

I keep getting an error saying "1061: Call to a possibly undefined method doDamage through a reference with static type flash.displayisplayObject."!

It just won't work. I've tried altering the code to:

game["person"+i].doDamage(redDot);

but I get an unexpected trace output saying "TypeError: Error #1010: A term is undefined and has no properties."

View 6 Replies

ActionScript 3.0 :: Accessing Properties Of Embedded SWFs

May 31, 2009

Is it possible to access variables or even functions of an embedded SWF? (One which has been embedded manually and has not loaded from somewhere)For example, I embed an swf called Movie1 which contains a string variable declared in its root, would it be possible for the parent SWF to access that string?

View 1 Replies

ActionScript 3.0 :: Accessing Properties Of The Document Class?

Nov 14, 2009

when I try to access a property of the document class from another class, I get an error:

Quote:

1119: Access of possibly undefined property _left through a reference with static type flash.displayisplayObject.

Maybe I'm not doing it correctly? This is how I've been accessing document class properties so far. Does the fact that they're private make a difference?

Quote:

root.property

View 1 Replies

ActionScript 3.0 :: Accessing Properties Of External MXML?

Sep 16, 2010

I have written "components" in external .mxml files like dialogs and such. For example, GamePropertiesDialog.mxml. These components are used by another file, Main.mxml for example. If I instantiate a GamePropertiesDialog I am unable to access its pieces like a textbox with an id of GameName until AFTER I add the dialog to the display list.Doesn't work:

Actionscript Code:
var tmp:GamePropertiesDialog = new GamePropertiesDialog();tmp.GameName.text = 'test';addChild(tmp);

Does work: Actionscript Code:
var tmp:GamePropertiesDialog = new GamePropertiesDialog();addChild(tmp);tmp.GameName.text = 'test';

View 1 Replies

ActionScript 3.0 :: Document Class, And Accessing Properties?

May 25, 2009

I'm currently working on an interactive app, (site) which requires me to modify a few textfields, and change images dependant on the user choice (using mouseevent). This is a separate module, thus I'm posting the question in here instead:there are three images, that are lined up, with a textbox next to them. When a image is chosen, and enlarges, the text changes with the chosen image, according to XML.The textFields, 'text_title', 'text_description' are contained in a movieclip, called 'textbox'.This has been built in the Flash IDE (CS3) named info.fla/swf, which refers to a Document class 'com.info', made in Flex Builder 3...I attempted to modify the textfields using this:textbox.txt_title.text = "Loading";textbox.txt_desc.text = "test";But, I was unable to at first to change the text using the document class, as it gives "1120: Access of undefined property <variable>".

View 3 Replies

ActionScript 3.0 :: Accessing Some Properties Of A Custom Component?

Jan 15, 2009

I have been stuck on this problem for a while, and wonder if anyone knows the answer. It is concerning accessing some properties of a custom component. I marked the problem with the keyword [PROBLEM] in the following snippets of code.

components/State1UI.mxml
--------------------------------
<?xml version="1.0" encoding="utf-8"?>

[code].....

View 0 Replies

ActionScript 3.0 :: Accessing Properties Of The Stage From A Class?

Aug 29, 2009

I am trying to access the x and y properties of the stage so I can set an objects' x and y properties to place it on the center of the stage:

this.x=stage.stageWidth/2;
this.y=stage.stageHeight/2;
The call to instantiate the object(*.fla):

[code]......

View 4 Replies

ActionScript 2.0 :: Accessing Properties Of Movie Clip?

Apr 26, 2010

I have the following prob :

I created several instance of the same MC like this

[Code].....

View 1 Replies

ActionScript 3.0 :: Accessing Properties And Methods Of External SWF

Oct 2, 2011

I can't access the props and methods of an external AS3 swf after it's loaded by Main.as. Here's a very simplified version of the code for Main.as (the calling swf):

Code:
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;
public class Main extends Sprite{
private var imgLoaded:Boolean = false;
[Code] .....

View 5 Replies

ActionScript 3.0 :: Accessing Properties From Stage In A Class?

Feb 28, 2012

I am trying to access a property that belongs to the stage, from a class. For example, let's say I add a textfield with an instance name of "magic_txt" on the stage. In the Document Class, I am able to access magic_txt and update the field like so:

magic_txt.text = "Magic Text"

However, since I would like to work in classes, I am having a difficult time figuring out how to access the property "magic_txt.text" from a class. I know I need a reference, but I am unsure how to set this reference.

I am coming from a strong background in Visual Basic, and in Visual Basic, the way to access a form property is to call the form name (dot) object. In actionscript, it doesn't seem to be as simple.

View 9 Replies

ActionScript 3.0 :: Accessing Properties For An Mc In An Externally Loaded Swf?

May 24, 2010

I am trying to set a couple of properties (specifically width and height) for an mc within an externally loaded swf but am having bigtime troubles. Keep getting the 'Error #1010: A term is undefined and has no properties'. The code is attached below. I have tried to figure this out and searched for solutions but could not resolve this myself.

import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;

[code]......

View 1 Replies

ActionScript 2.0 :: Accessing (Nested) Component Properties From Class

Jul 29, 2009

(Actionscript 2 btw - and actually cs4, not that it really makes any difference?) I have a class that instantiates a movieclip from the library, e.g.:
Code:
debugbar:MovieClip = thing.AttachMovie("debugbar", "debugbar_mc", 999);
So attaching it to the where ever "thing" is - could be movie clip or level0 or whatever, doesn't matter as "debugbar" is a private variable of the class. Now the important part - debugbar in the library is a movieclip that contains some components - buttons and textInputs. The problem comes when trying to access these components.

I would have thought that this would work:
Code:
debugbar.input_txt.text = "hello";
In order to set the text of "input_txt", the instance name of a TextInput component on the timeline of the movie clip (put there in author time). However, this does not work. Infact, I cannot access any specific "component" properties - they come back undefined. I can however set and retrieve MovieClip properties for the "input_txt", such as _x. However there is one added strange thing with this too - setting _visible to false doesn't seem to work (however perhaps a component by default overrides this).

I also appear not to be able to add event handlers to the component - at least for the usual component events. I tried casting it to a component, such as:
Code:
var temp:TextInput = TextInput(debugbar.input_txt);
trace(temp);
which gave "temp" as null.
However if you trace the thing itself without casting to what it is, it gives the path to correctly. It almost seems like the components are somehow broken when trying to access them this way - or that they cannot be accessed this way?

The thing is, I was able to access all of this before, when the code to do it was placed on the timeline (frame 1, the only frame) of the debugbar itself, where the components were child instances. This meant I could just reference them directly too - so input_txt rather than debugbar.input_txt , although that is probably largely irrelevant. I need to have it in a class though, as I need to pass in certain objects that need to be accessed by the mc.

View 2 Replies

ActionScript 3.0 :: Accessing Child Properties Of Items In A Container?

Jun 8, 2011

Basically, I have a menu created using XML. Each menu item has a fill that fades in and out as the user scrolls over them. What I want to happen is that when an item is clicked, it stays highlighted. The problem comes when I click on the second item. I can't get the first item to "unselect."Here is the menu code and functions.

Code:
var menuHolder:MovieClip = new MovieClip();
menuHolder.x = myMask.x;

[code].....

View 6 Replies

ActionScript 3.0 :: Accessing Movieclip Properties Which Are Created During Runtime?

Mar 9, 2011

how to access the properties of the movieclips which are created during runtime.

Ex:
var dotCount:uint = 0;
for(var i:uint = 0; i<=10;i++)
{
var circle:MovieClip = new MovieClip();

[Code]....

How can I access a property (say .alpha or any other property) of "circle6"??

View 2 Replies

Flex :: Accessing Properties Of AdvancedDataGrid Runtime Vs Design Time

Jun 12, 2011

I am new to Flex and trying to modify some existing code.I am trying to It uses and Advanced DataGrid. In the click event, the ListEvent is passed in, and the code is able to access properties such as event.itemRenderer.data.feature.I would like to check whether the user has clicked on a parent (group) record or the child record; at runtime, I can see that the property I want to access is event.itemRenderer.listData.hasChildren. However, the listData property of itemRenderer does not show up in intellisense, and when I try to access that at design time, the project will not build because of the error "Access of possibly undefined property listData". But the property .data.feature doesn't show up in intellisense at design time either, and that builds and runs just fine.

What do I need to do to access event.itemRenderer.listData without throwing errors when I build the project? Do I need to capture a different event, or cast the event object or one of its properties into another object that will have the properties I need at runtime (I've investigated these options but cannot find info on how to do that).

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved