Hi All,

I'm currently creating my own imagecomponent, which has 4 states:
  * image : display the image
  * text  : display the uri
  * edit  : display uri in an inputfield
  * both  : display image+uri

The idea is that when a non-edit-state is double-clicked, the
editstate gets activated and my user can provide a new uri for the image.

What I've done so far (stripped code, only states text and edit)

//*start of code*//
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";
        currentState="text"
        creationComplete="init()"
        doubleClickEnabled="true"
>

        <mx:Script>
                <![CDATA[
                        //possible states
                        public static var STATE_TEXT:String = "text";
                        public static var STATE_EDIT:String = "edit";
                        
                        [Bindable]
                        public var imgURL:String;
                        
                        //holds previous state
                        private var prevState:String;
                        
                        private function init():void
                        {
                                this.addEventListener(MouseEvent.DOUBLE_CLICK, 
switchToEditState);
                        }
                        
                        private function 
switchToEditState(event:MouseEvent):void
                        {
                                this.prevState = this.currentState;
                                this.currentState = Image.STATE_EDIT;
                                
this.editImage.addEventListener(FocusEvent.FOCUS_OUT,
focusOutOfEditHandler);
                                
this.editImage.addEventListener(KeyboardEvent.KEY_DOWN,
keyboardDownHandler);
                        }
                        
                        private function 
focusOutOfEditHandler(event:FocusEvent):void
                        {
                                restoreState();
                        }
                        private function 
keyboardDownHandler(event:KeyboardEvent):void
                        {
                                //if enter was pressed
                                if (event.charCode == 13)
                                        restoreState();
                        }
                        private function restoreState():void
                        {
                                this.currentState = this.prevState;
                        }
                        
                ]]>
        </mx:Script>

<mx:states>
        <!-- display the url as text //-->
        <mx:State name="text">
                <mx:AddChild>
                        <mx:Text text="{this.imgURL}" />
                </mx:AddChild>
        </mx:State>
        <!-- display an editable textbox //-->
        <mx:State name="edit">
                <mx:AddChild>
                        <mx:TextInput id="editImage" text="{this.imgURL}" />
                </mx:AddChild>
        </mx:State>
</mx:states>
</mx:Canvas>
//*end of code*//

However this gives me unexpected behaviour.
If you double-click on the text, the edit-field shows up with the
correct content. Then you alter this field and focus out of it, so the
text-view appears instead.
However the text-view is not changed.  (In the meantime I do realize
that the curly braces only bind in one direction, but besides that)
The really wierd thing is that, when going back into the edit-state,
the inputfield DOES contain my altered value...

Can anyone clarify this behaviour out for me, because I don't see
where the altered value can be saved, except for the variable imgURL.
But if that is the case, then why isn't the text-view updated?

Kind regards,
--Johan

PS: does anyone know a free host to upload a swf, it could make
examples in here lots easier :)

Reply via email to