Custom Object Parameter

Is there a way to add a custom parameter to an object after it's on stage? I tried:

Code:
world1.mycir.paramname = 'text'


But when I try to call this parameter in an if inside a function for onContact it says it can't find the parameter. Is there another way?
Yes, if I do remember correctly you can use box2d's userData var.

object.b2body.SetUserData("data")

then

myVar = object.b2body.GetUserData()

Also you could just use flash's naming var if you're not already using it (if you're using var name like you should.)

object.name = "data"
I tried the

object.name = "data"

But when I do the IF I get a error in Flash saying that the parameter field doesn't exist.
DON'T set the userdata of the b2Body! This needs to point to the BodyShape for things like contact events to work correctly.

The best way to add properties is to extend BodyShape with your own class and add public variables.

If you define a "ShapeBase" class that extends BodyShape at the root of your project, properties added to this class will be added to all shape.* instances.
Ok, I'm still learning with this thing ha ha, where do I do that?
mayobutter wrote:
DON'T set the userdata of the b2Body! This needs to point to the BodyShape for things like contact events to work correctly.

0.o

jfreak53 wrote:
Ok, I'm still learning with this thing ha ha, where do I do that?

Ok that's an as3 thing, basically make a new class the extends BodyShape, I use GameShape for mine. Then leave public vars in there and crate new instances of GameShape for your game. The only draw back to that that I've seen is that you have to pass fixtures to it I'm pretty sure.

This all assumes you're using as3 and OOP approach to your game. If you picked up WCK thinking it'd be a cheat outta coding then you're wrong. XD
Ok thanks, thought you meant I had to edit the code for the Shape object and add a new class in it's original file. No I was expecting to code just can't find any real documentation on this system, documentation that actually follows an API system, that shows each function for each object in it's proper order. If I could find documentation for it that showed objects and their resulting functions or methods I could follow, but I can't find that.
jfreak53 wrote:
Ok thanks, thought you meant I had to edit the code for the Shape object and add a new class in it's original file. No I was expecting to code just can't find any real documentation on this system, documentation that actually follows an API system, that shows each function for each object in it's proper order. If I could find documentation for it that showed objects and their resulting functions or methods I could follow, but I can't find that.


It doesn't exist. There's no docs for WCK. I'm still confused by a lot of even the basic functions.

Original thread: https://box2d.org/forum/viewtopic.php?t=6977