-
call function based on xml value
i have a repeater :
PHP Code:
<mx:Repeater id="btnRepeater" dataProvider="{rep.currentItem.BUTTON}">
<mx:Button label="{btnRepeater.currentItem}" click="getDefinitionByName('{btnRepeater.currentItem.@EVENT}')"/>
</mx:Repeater>
and i want to call some how to a function with a value i get from the xml:
getDefinitionByName('{btnRepeater.currentItem.@Fun ctionName}')
anu idea?
-
Senior Member
Here is just a few ideas:
Create a function to parse the function name:
Actionscript Code:
function ParseFunction(name:String):void{ switch(name){ case "function1": function1(); break; case "function2": function2(); break; case "function3": function3(); break; case "function4": function4(); break; default: trace("Parse Failed: Missing Function Name \""+name+"\""); break; } }
OR you can do this
Actionscript Code:
try{ this[name]();//'this' being the scope of the class from where the methods/functions are located. }catch{ trace("Rut Row"); }
The second way is a bit cheeky, but really easy to get running. This makes debugging a great deal harder when stuff is missing or not running.
The first way takes a lot of writing- but gives you more direct control over what is happening.
Hope that helps =P
GK >^,^<
-
but what should be done in the repeater?
this isnt working :
Actionscript Code:
getDefinitionByName('{btnRepeater.currentItem.@EVENT}')
-
Actionscript Code:
var xmlData:XML= <root> <functionName>randomNumber</functionName> <functionName>sortNumber</functionName> </root>; var xmlList:XMLList=xmlData.children(); var arr:Array=new Array();
function randomNumber(min,max) { return Math.round(Math.random() * max - min + 1 + min); } function sortNumber(a,b) { if (a<b) { return -1; } else if (a>b) { return 1; } else { return 0; } }
for (var i:int=0; i<10; i++) { arr.push(this[xmlList[0]](4*i,10*i)); } //-------------------------------------------- trace(arr); trace(arr.sort(this[xmlData.children()[1]])); //--------------------------------------------
marlopax
-
how does you code help?
i dont want to parse the xml, rather i want to get the data as part of the repeater
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|