I’ve just started with OOP in AS2 and have gone through moocks book covering the subject. I’ve come to the point where I want to begin doing my own stuff and have caught myself up on an annoying detail concerning using the mvc design pattern and applying simple movieclip events to instances. For the sake of simplicity I’ve created a movieclip with a drawn rectangle in the view object. I’m attempting to catch an onPress event with that and send it to the controller object which in turn just traces the event. Here’s the code for BarView.as:
import util.;
import mvcbar.;
import mvc.*;
class mvcbar.BarView extends AbstractView {
private var crossbar_mc:MovieClip;
public function BarView (m:Observable,
c:Controller,
target:MovieClip,
depth:Number,
w:Number,
h:Number) {
super(m, c);
// Create UI.
makeBar(target, depth, w, h);
}
public function defaultController (model:Observable):Controller {
return new BarController(model);
}
public function makeBar (target:MovieClip,depth:Number,w:Number,h:Number):Void {
crossbar_mc = target.createEmptyMovieClip("crossbar_mc", depth);
// Store a reference to the movieClip.
crossbar_mc = target.crossbar_mc;
/**
- Rectangle drawing code comes here
*/
crossbar_mc.onPress = crossbar_mc.addEventListener(“onPress”, getController());
}
public function update (o:Observable, infoObj:Object):Void {
var info:BarUpdate = BarUpdate(infoObj);
}
}
…and there’s an onPress function in the BarController object instace waiting to be called, but with no success. Is there a better routine to go about using the mvc model with movieclip events? All I have stumbled upon is attaching components and receiving calls from them.