Hi
I'm an moderately experienced Silverlight programmer and I'm just starting with Flex. I'm beggining to understand the language but I'm running at problems trying to accomplish similar tasks in Flex.
1) Flex can declare a variable as type Function but can it declare a variable as a specific function? (i.e. a C# delegate)
For example
Is the following possible where SomeFunction is defined elsewhere? If so how is SomeFunction defined.
var value:SomeFunction;
2) I understand the syntax "var value:*" but what is the name for this type of declaration?
3) Does Flex support abstract classes? Does Flex support abstract methods?
4) Does Flex support reflection (i.e. querying an object type definition)? If so how does this work?
5) Is it possible to convert value in "var value:*" to a string for debugging (i.e. dump the properties and their values to the trace command)?
Thanks
Hi
1) Flex can declare a variable as type Function but can it declare a variable as a specific function? (i.e. a C# delegate)
For example
Is the following possible where SomeFunction is defined elsewhere? If so how is SomeFunction defined.
var value:SomeFunction;
Do you mean this:
var traceParameter:Function = function (aParam:String)
{
trace(aParam);
};
traceParameter("hello"); // hello
or
function traceParameter(aParam:String)
{
trace(aParam);
};
var otherFunction:Function = traceParameter;
you can find more in the flex help under Functions
2) I understand the syntax "var value:*" but what is the name for this type of declaration?
I'm not quite sure about this one but I just simple call it * type(very creative
)
3) Does Flex support abstract classes? Does Flex support abstract methods?
No, it doesn't support abstract classes... but there is some sort of workaround, in your "Abstract" Class create the methods and in each abstract method just thorw an Error indicating that this method has to be overriden
4) Does Flex support reflection (i.e. querying an object type definition)? If so how does this work?
Yes, look in the help for getDefinitionByName and getQualifiedClassName... here is a Sample to dinamically create a class
var ClassReference:Class = getDefinitionByName(getQualifiedClassName(entity)) as Class;
var tmpClass:* = new ClassReference();
you can also get the class attributes by calling
describeType() wich returns a XML with the class definition or calling ObjectUtil.getClassInfo
also, you can use a string to query an object lets say, person["name"] is the same of using person.name, it is pretty dynamic but not recomended for performance and code bad practice reasons...
5) Is it possible to convert value in "var value:*" to a string for debugging (i.e. dump the properties and their values to the trace command)?
I haven't tested this one but you could cast the object to String -> String(value) or try the toString method
Hope some of this can be usefull
Gus
North America
Europe, Middle East and Africa
Asia Pacific