Friday, October 17, 2008

Passive View in Flex

Those interested in implementing the Model View Presenter design pattern with a Passive View should find the following (abbreviated) code of benefit.
  1 <?xml version="1.0"?> 
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
3 creationComplete="_onCreationComplete()"
4 implements="org.hertler.photo.photocontroller.IPhotoView">
5 <mx:Script><![CDATA[
6 import org.hertler.photo.photocontroller.IPhotoPresenter;
7 import org.hertler.photo.photocontroller.PhotoPresenter;
8
9 private var _photoPresenter:IPhotoPresenter;
10
11 private function _onCreationComplete():void {
12 _photoPresenter = new PhotoPresenter(this);
13 }
14
15 private function submitDofHandler(event:Event):void {
16 _photoPresenter.onSubmit();
17 }
18
19 public function get subjectDistance() : String {
20 return txt_subjectDistance.text;
21 }
22 public function set subjectDistance(subjectDistance:String) : void {
23 txt_subjectDistance.text = subjectDistance;
24 }
25
26 ]]></mx:Script>
27 <mx:Panel title="Depth of Field Calculator" height="75%" width="75%"
28 paddingTop="10" paddingLeft="10">
29 <mx:Grid id="grid_input" horizontalAlign="left" width="100%">
30 <mx:GridRow>
31 <mx:GridItem horizontalAlign="right">
32 <mx:Label text="Subject Distance"/>
33 </mx:GridItem>
34 <mx:GridItem>
35 <mx:TextInput id="txt_subjectDistance" text="10"/>
36 </mx:GridItem>
37 <mx:GridItem>
38 <mx:Label text="meters"/>
39 </mx:GridItem>
40 </mx:GridRow>
41 </mx:Grid>
42 </mx:Panel>
43 </mx:Application>


Line 4: this is how an ActionScript interface is implemented in a mxml file
Line 12: we construct the Presenter whose constructor takes a IPhotoView
Line 16: immediately hand off events to the Presenter




Labels: ,


Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]