Marc Hughes


Home
Blog
Twitter
LinkedIn
GitHub
about
I am a developer from a bit west of Boston.

Using Moccasin with Flex 4

11 Jan 2007

I started up a new project last night using Moccasin and Flex 4. 

I was worried about the amount of changes I might have to make to a framework like Moccasin to use it with Flex 4. So far, the only change I had to make, using the Simple World application as a starting point, was to remove a reference to Application.application in com.joeberkovitz.moccasin.editor.MoccasinEditor.  I added a parameter to initializeEditor() to specify a stage object on which to add the event handler to.  Since stage is the same class for Halo and Spark apps, it should work in either.  I think it'll catch events at more or less the same level.

In Moccasin Editor:

public function initializeEditor(stage:Stage):void
    {
     controller = createController();
     var keyMediator:EditorKeyMediator = createKeyMediator(controller);
     documentService = createDocumentService();
      

// aggressively funnel keystrokes into our key mediator stage.addEventListener(KeyboardEvent.KEYDOWN, keyMediator.handleKey); addEventListener(KeyboardEvent.KEYDOWN, keyMediator.handleKey);

viewLayer.scaleX = viewLayer.scaleY = viewScale;

 setFocus();

 if (configurationService.documentUri != null)
 {
  loadDocument(configurationService.documentUri);
 }
}</pre></p><p>In Simpleword...AirAppEditor</p><p><pre lang="actionscript">override public function initializeEditor(stage:Stage):void

{ super.initializeEditor(stage); loadFromDocumentData(new MoccasinDocumentData(new ModelRoot(new World()), null)); }

In your main application mxml

private function onCreationComplete():void
{
  // Create a configuration service to provide startup defaults to the editor
  editor.configurationService = new BasicConfigurationService(null, null);
  // initialize the editor and its menu bar
  editor.initializeEditor(stage);
  editorMenuBar.editor = editor;
}