A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: call function based on xml value

  1. #1
    Junior Member
    Join Date
    Aug 2003
    Posts
    5

    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?

  2. #2
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    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 >^,^<

  3. #3
    Junior Member
    Join Date
    Aug 2003
    Posts
    5

    but what should be done in the repeater?

    this isnt working :
    Actionscript Code:
    getDefinitionByName('{btnRepeater.currentItem.@EVENT}')

  4. #4
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    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

  5. #5
    Senior Member
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    287

    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center