In an effort to make DObject updates easier to react to in actionscript, gendobj now generates
signals for each field that can be listened to individually.
From the old:
barrel.addListener(new AttributeChangeAdapter(function (event :AttributeChangedEvent) :void {
if (event.getName() == BarrelObject.MONKEY_COUNT) {
// ... cast event.getValue() and use it
}
}));
to the new:
barrel.onMonkeyCountChanged.add(function (newValue :int, oldValue :int) :void {
// ...
});
Only AttributeChangedEvent have been signalified, but I'm planning to continue with the other
ChangeListeners shortly.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6328 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,6 +21,10 @@ public class {{classname}} {{^extends.isEmpty}}extends {{extends}}
|
||||
|
||||
{{/fields}}
|
||||
{{#dobject}}
|
||||
{{#fields}}
|
||||
public var {{name}}Changed :Signal = new Signal({{simpleType}}, {{simpleType}});
|
||||
{{/fields}}
|
||||
|
||||
{{#fields}}
|
||||
public static const {{dobjectField}} :String = "{{name}}";
|
||||
|
||||
@@ -47,7 +51,52 @@ public class {{classname}} {{^extends.isEmpty}}extends {{extends}}
|
||||
{{/fields}}
|
||||
}
|
||||
{{/dobject}}
|
||||
|
||||
{{#dobject}}
|
||||
public function {{classname}} ()
|
||||
{
|
||||
new Signaller(this);
|
||||
}
|
||||
{{/dobject}}
|
||||
// GENERATED STREAMING END
|
||||
|
||||
// GENERATED CLASSFINISH START
|
||||
}
|
||||
}
|
||||
// GENERATED CLASSFINISH END
|
||||
|
||||
{{#dobject}}
|
||||
// GENERATED SIGNALLER START
|
||||
import org.osflash.signals.Signal;
|
||||
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||
|
||||
import {{package}}.{{classname}};
|
||||
|
||||
class Signaller
|
||||
implements AttributeChangeListener
|
||||
{
|
||||
public function Signaller (obj :{{classname}})
|
||||
{
|
||||
_obj = obj;
|
||||
_obj.addListener(this);
|
||||
}
|
||||
|
||||
public function attributeChanged (event :AttributeChangedEvent) :void
|
||||
{
|
||||
var signal :Signal;
|
||||
switch (event.getName()) {
|
||||
{{#fields}}
|
||||
case "{{name}}":
|
||||
signal = _obj.{{name}}Changed;
|
||||
break;
|
||||
{{/fields}}
|
||||
}
|
||||
signal.dispatch(event.getValue(), event.getOldValue());
|
||||
}
|
||||
|
||||
protected var _obj :{{classname}};
|
||||
}
|
||||
// GENERATED SIGNALLER END
|
||||
{{/dobject}}
|
||||
|
||||
Reference in New Issue
Block a user