Results 1 to 4 of 4

Thread: Provide mass properties to an object in AS3

  1. #1
    Join Date
    Nov 2009
    Posts
    47

    Provide mass properties to an object in AS3

    Is there a quick fix in AS3 to give mass properties to an object during its instantiation?

    I want to avoid repeatably making myObject.myProperty = value ...

    For example, the Away3D framework, we can define the properties of a newly created cube this way:
    Code:
    var myCube:Cube = new Cube ( { x: 2 , y: 3 , z: 15 , alpha: 0.5 , rotationY: 62 , width : 35 , ... } ) ;
    All in order you want of course. Is there the equivalent in native AS3? How can I do if I create a function myself ?

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Provide mass properties to an object in AS3

    You could do with ... args

    genre:
    function test(...args)
    test(x, v, t ,t ,t ,t ,t, ,t ,t, e,e, e ,e)

    and you RECOVERED ls value to the table with "args"

    Examples of arguments:

    Code:
    myMethod ( "Hello" , "World" ) ; function myMethod ( str: String , str2: String ) : void { trace ( arguments . callee == this . myMethod ) // true trace ( arguments . length ) ; // 2 trace ( arguments [ 0 ] ) ; // Hello trace ( arguments [ 1 ] ) ; // World trace ( str,str2 ) ; // Hello World }
    The callee property returns a reference to the function that called the method. To handle errors, there is also a class ArgumentError.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Provide mass properties to an object in AS3

    Well, I do not know anything about AS3, but it is much like your JavaScript code.

    If it's the same thing, you can declare an object with JSON, like:
    Code:
      var MYCUBE = (x: 2 y: 3 z: 15, alpha: 0.5, rotationY: 62 width: 35)
    It'll create an object with properties MYCUBE x, y, z, alpha, width and rotationY already declared.

    If you want to add properties to an existing object, use either a function and route table "arguments", or duplicate the properties of an object ad-hoc. For example, to copy the properties of "MYCUBE" in an object "myObject", use:
    Code:
      for (var i in MYCUBE) 
      myObject [i] = MYCUBE [i]
    Or via a function:
    Code:
    function addProp(myObject)
    {
        for (var i = 1; i < arguments.length; i += 2)
            myObject[arguments[i]] = arguments[i+1]
    }
    Who used this way:
    Code:
    addProp(myObject, "x", 2, "y", 3, "z", 15, "alpha", 0.5, "rotationY", 62, "width", 35)

  4. #4
    Join Date
    Nov 2009
    Posts
    47

    Re: Provide mass properties to an object in AS3

    Well, I knew this "JSON" nomenclature as you said, but I never tested in AS3, and it works fine, thank you DotNetUser for your input

    Code:
    function addProp (_cible:Object, _properties:Object)
    {
            for (var i in _properties)
           _cible[i] = _properties[i]
    }
     
    addProp(myObject,{x:250,y:56});

Similar Threads

  1. Replies: 6
    Last Post: 06-06-2011, 01:34 AM
  2. Replies: 3
    Last Post: 08-01-2011, 06:20 AM
  3. How to use Properties object
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 05:49 AM
  4. Replies: 5
    Last Post: 05-01-2010, 05:42 PM
  5. Replies: 1
    Last Post: 16-12-2009, 01:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,947,833.80217 seconds with 16 queries