Model Issue

rottmanj's Avatar


14 May, 2010 06:07 PM

In my model I have the following code. After I create a new record the variable formTemplate is populated and the event CREATE_RESULT is fired. The issue that I am looking at is I would like to reuse this variable for other parts of the application.
IE editing, display, etc..

The issue as I see it is, the event will always be fired when the value is set.

package com.formdesigner.model

import com.formdesigner.vo.FormTemplates;

import org.robotlegs.mvcs.Actor;

public class FormTemplatesModel extends Actor

    private var _formTemplates:Array;
    private var _formTemplate:FormTemplates;
    private var _isCreate:Boolean = false

    public function FormTemplatesModel()

    public function set formTemplates(data:Array):void
        this._formTemplates = data;
        dispatch(new FormTemplatesEvent(FormTemplatesEvent.DATA_CHANGED));          

    public function get formTemplates():Array
        return this._formTemplates;

    public function set formTemplate(data:FormTemplates):void
        this._formTemplate = data;
        dispatch(new FormTemplatesEvent(FormTemplatesEvent.CREATE_RESULT));


  1. 1 Posted by Stray on 14 May, 2010 07:25 PM

    Stray's Avatar

    Hi Jeremy,

    sorry - your question / problem wasn't very clear. I understand what you have, just not what you're trying to do and why you think you can't do it.

    If you wanted the formTemplate variable to be available application wide then you could map it using injector.mapValue(FormTemplates, this._formTemplate), and then inject it in the other places you wish to use it. Of course these objects would need to only be created AFTER you've mapped the value, otherwise the object won't be there yet. (See the 3rd solution if this is a problem).

    Or... you could attach it as a property to the event that is fired when it's created.

    Or... you could inject a singleton here and in other places you need the template that is simply an access point for this value. FormTemplateHolder if you like. Crude but effective.

    Not sure if any of those fix your problem - write more if you need something different.


  2. 2 Posted by rottmanj on 14 May, 2010 08:06 PM

    rottmanj's Avatar

    You are right I should have been more clear.

    Starting off, after I create a new record the variable formTemplate is populated and then I change a view stack on my stage. This all works perfectly well.

    The issue I am having is that when I select a record I want to edit, I need to update formTemplate with the data in the model from the selected record. What I am trying to do is figure out how to just reuse the code above to achieve this with out dispatching the event in the setter.

  3. rottmanj closed this discussion on 10 Jan, 2011 12:21 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac