A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: matrix: just a dream?

  1. #1
    Member
    Join Date
    Oct 2001
    Location
    Italy
    Posts
    51
    Hallo!
    I'ld like to know if someone of you found a way to have a matrix-like variable.
    Maybe I have to build a custom object, but I'm not so good with object-oriented programming. Anyway, I could try it!
    Thank you in advance
    Carla

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    For the OOP things, it should be something like this:
    Code:
    _global.Matrix = function(a1, a2, b1, b2) {
    	this.a1 = a1;
    	this.b1 = b1;
    	this.a2 = a2;
    	this.b2 = b2;
    	this.double = function(x) {
    		return x*2;
    	};
    };
    y = new Matrix(1, 2, 3, 4);
    trace(y.a2);
    trace(y.double(y.b2));
    We can add math functions for the Matrix object.

  3. #3
    Member
    Join Date
    Oct 2001
    Location
    Italy
    Posts
    51
    Thank you Ericlin,
    but this seems an array to me, not a matrix.
    What I mean is to have an object whose elements can be reached by something like a[i, j], where i and j are integer indexes.
    To define an object like this there should be some command like
    m = new Matrix((4, 2, 7), (1, 0, 3), (5, 0, 1))
    so that I have an array of arrays.
    Is it possible?

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Initially I thought you want to make a class of Matrix that you can rotate. I mean a matrix of 2x2 or 3x3 or 4x4;

    If we need only arrays of arrays, Flash has already build-in functions to do multi-dimensional array; That is array of array; Only the syntax is slightly different from C language;

    m = [[4, 2, 7],[1, 0, 3],[5, 0, 1]];

    Then to access the third element of the first array will be:

    m[0][2]; That will be 7; In C, the syntax might be m[0,2];

  5. #5
    Member
    Join Date
    Oct 2001
    Location
    Italy
    Posts
    51

    Smile

    I love it!
    Thank you for providing me the right sintax.
    Carla

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