OOP Question & Camera3D

Software: Away3D 4.x

export, Newbie
Posted: 20 December 2012 08:41 PM   Total Posts: 1

hi away3d community,

i hope this question isn’t too low level. i’ve got two objects, A and B. A has data that needs to be delivered to B. my friend thinks its okay to use events to pass the data, since C and D also need it. shouldn’t i just use some sort of data passing function? like:

B.setFoo(A.bar);
C.setFoo(A.bar);
D.setFoo(A.bar); 

rather than

B.addEventListener(BarEvent.CONSTANTonBar);
C.addEventListener(BarEvent.CONSTANTonBar);
D.addEventListener(BarEvent.CONSTANTonBar);
A.dispatch(new BarEvent(BarEvent.CONSTANTfoo)); 

??

i ask it here because in Camera3D, LensEvent appears to be doing the latter and my friend is using this as a justification for what i suspect is incorrect programming practice.

   

Rasterizer, Member
Posted: 21 December 2012 04:54 PM   Total Posts: 69   [ # 1 ]

The usage depends on a few things.

1, are the objects in question instantiated ? 100% totally sure ?
2, can you depend on either object being usable that way at the time you would like to call that method ?

If there is an uncertainty over the object’s being instanced or ready, it is better to use events. It’s better for an object to miss an event than blessing your user with a runtime error. You need to structure your code carefully and it will all make sense when to use which approach.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html

http://active.tutsplus.com/tutorials/actionscript/as3-101-events-basix/

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X