Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-11-2009
Member
 
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 ?
Reply With Quote
  #2  
Old 18-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #3  
Old 18-11-2009
Member
 
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)
Reply With Quote
  #4  
Old 18-11-2009
Member
 
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});
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Provide mass properties to an object in AS3"
Thread Thread Starter Forum Replies Last Post
Getting HP AIO Device object server register class object failed message on my system Donoho Hardware Peripherals 6 06-06-2011 01:34 AM
Scope of Object or variable in Object oriented Programming Languages Dėfrim Software Development 3 08-01-2011 06:20 AM
How to use Properties object Ash maker Software Development 5 10-02-2010 05:49 AM
Explain the important Methods and Properties of the XMLHttpRequest object Izek Software Development 5 05-01-2010 05:42 PM
property error message "you do not have sufficient privilages for configuring connection properties." for trying to look up properties for my dial up and it's on VISTA AK_fisherman Technology & Internet 1 16-12-2009 01:11 PM


All times are GMT +5.5. The time now is 10:35 AM.