converting class to normal code
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: converting class to normal code

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2

    converting class to normal code

    i would like to know if theres a way to write this code without the need of a class?

    bodydata is an array:
    Code:
    var bodydata = new Array();
    and the line i want to use:
    Code:
    bodydata.push(new bodycalc("178,80"));
    but to use it i need this class:

    Code:
    class bodycalc
    {
        var height, weight;
        function bodycalc(str)
        {
            var _loc1 = str.indexOf(",", 0);
            height = Number(str.substr(0, _loc1));
            weight = Number(str.substr(_loc1 + 1, str.length));
        } // End of the function
    } // End of Class
    i would like to do the same but without the class, is that possible?
    so i can use bodydata[0].height, bodydata[1].weight and so on...

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    PHP Code:
    var bodydata:Array = new Array();

    function 
    bodycalc(str) {
        var 
    data=str.split(",");
        return {
    height:data[0],weight:data[1]};
    }

    bodydata.push(bodycalc("178,80"));
    bodydata.push(bodycalc("18,440"));

    trace(bodydata[0].height);
    trace(bodydata[0].weight);
    trace("-------");
    trace(bodydata[1].height);
    trace(bodydata[1].weight); 

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    i have now tested the code and its working! thanks a lot!

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

Poll by Flashkit.com