I've been experimenting with user interaction and Cairngorm, and have
found that associating component properties (selectedIndex,
verticalScrollPosition) to a bound ModelLocator isn't as reliable as
passing views to value objects and setting these properties in
commands.
A scenario: I fetch data from my server to populate a DataGrid. The
grid's mxml looks more or less like this:
<mx:DataGrid verticalScrollPosition="{model.commentScrollPos}"
selectedIndex="{model.commentSelectedIndex}" id="comments_dg"
itemClick="comments_dg_itemClickHandler()" width="100%" height="100%"
dataProvider="{model.comments}"/>
When the data arrives, I set these properties in the Model:
public function onResult( event:* = null ):void {
if( event.result ) {
var model:ModelLocator = ModelLocator.getInstance();
model.workflowState = ModelLocator.DEFAULT;
model.commentVO = CommentVO( event.token.commentVO );
model.comments = new ArrayCollection( ArrayUtil.toArray(
event.result ) );
switch(event.token.commentVO.comment_requestType) {
case "forLatest":
for (var i:Number = 0; i<model.comments.length;
i++) {
if (model.comments[i].comment_id ==
event.token.commentVO.comment_id) {
model.commentSelectedIndex = i;
var scrollMultiplier:Number = i;
}
}
model.commentScrollPos =
Math.ceil(scrollMultiplier*model.commentsView.rowHeight);
break;
case "onSubmit":
model.commentScrollPos =
model.commentsView.maxVerticalScrollPosition;
model.commentSelectedIndex =
model.comments.length;
break;
default:
model.commentScrollPos = 0;
model.commentSelectedIndex = 0;
break;
}
} else {
Alert.show( "No Data Found" );
}
}
The consistency of this technique is pretty erratic. Anyone
experience the same thing, or something similar? Should I go back to
passing my views (Datagrids, etc) into value objects?
Mike Britton
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/