topical media & game development

talk show tell print

lib-flex-ximpel-editor-net-ximpel-components-MediaClipForm.mx

lib-flex-ximpel-editor-net-ximpel-components-MediaClipForm.mx (swf ) [ flash ] flex


  <?xml version="1.0" encoding="utf-8"?>
  <!-- 
      This program is free software: you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation, either version 3 of the License.
  
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
  
      You should have received a copy of the GNU General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
          Javier Quevedo Fernández 05-2009.
  -->
  <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
           horizontalScrollPolicy="off" creationComplete="init();">
          <mx:Script>
                  <![CDATA[
                          import mx.events.FlexEvent;
                          import mx.events.StateChangeEvent;
                          import mx.containers.FormItem;
                          import net.ximpel.classes.MediaClip;
                          import net.ximpel.classes.Subject;
                          import net.ximpel.components.MediaClipView;
                          import net.ximpel.classes.Helper;
                          import mx.binding.utils.BindingUtils;
                          public var subjectView : SubjectView;
                          [Bindable]
                          public var currentMediaClip : MediaClip;
                          
                          
  
                          private var subjects : Array;
                          private var firstRun : Boolean = true;
                          private var fileReference : FileReference;
                          public function init():void {
  
                          }
          
              private function toId(element:Subject, index:int, arr:Array):String {
                  return element.id;
              }        
                          public function updateClip(clip : MediaClip, _subjects : Array):void{
                                  if (!firstRun){
                                          leadsTo.removeEventListener(FlexEvent.VALUE_COMMIT, leadsToChangeHandler);
                                  }
                                  firstRun = false;
                                  currentMediaClip = clip;
                                  this.subjects = _subjects;
                                  
                                  // The form must be recreated else the Bindings do not work correctly.
                                  recreateForm();
                                  
                                  this.source.text = clip.file;
                                  this.extra.selected = clip.extra;
                                  this.repeat.selected = clip.repeat
                                  leadsTo.dataProvider = _subjects.map(toId);  
                                  leadsTo.selectedIndex = -1;        
                                  if (clip.leadsTo)
                                          this.leadsTo.text = clip.leadsTo.id;
  
                                  BindingUtils.bindProperty(clip, "file", this.source, "text");
                                  BindingUtils.bindProperty(clip, "repeat", this.repeat, "selected");
                                  BindingUtils.bindProperty(clip, "extra", this.extra, "selected");
                                  
                                  leadsTo.addEventListener(FlexEvent.VALUE_COMMIT, leadsToChangeHandler);
                                  //leadsTo.addEventListener(E
                                  //var __subject : Subject = helper.getSubject(subjects, this.leadsTo.text);
                                  //BindingUtils.bindProperty(clip, "leadsTo". helper.getSubject(subjects, this.leadsTo.text), null); 
                                  //BindingUtils.bindProperty(clip.leadsTo, "id", this.leadsTo, "text");
                          }
                                  
                          private function selectFileHandler(event:Event):void{
                                  var fileReference : FileReference = FileReference(event.currentTarget);
                                  source.text = fileReference.name;
                          }
                          
                          
                          private function onSelectSource(event:Event):void{
                                  fileReference = new FileReference();
                                  fileReference.addEventListener(Event.SELECT, selectFileHandler);
                  fileReference.browse();
                          }
  
                          private function leadsToChangeHandler(event:Event):void{
                                  var __subject : Subject = Helper.getSubject(subjects, this.leadsTo.text);
                                  if (__subject.id != "none")
                                                  currentMediaClip.leadsTo = __subject;
                                  else
                                          currentMediaClip.leadsTo = null;
                          }
                          
                          private function recreateForm():void{
                                  var _formItem : FormItem;
                                  form.removeAllChildren()
                                  
                                  
                                  _formItem = new FormItem();
                                  _formItem.label = "Source";
                                  form.addChild(_formItem);
                                  source = new TextInput();
                                  source.width=105;
                                  _formItem.addChild(source);
                                  _formItem.addChild(sourceButton);
                                  
                                  
                                  _formItem = new FormItem();
                                  form.addChild(_formItem);
                                  extra = new CheckBox();
                                  extra.label = "Extra";
                                  extra.percentWidth= 100;
                                  _formItem.addChild(extra);
  
                                  _formItem = new FormItem();
                                  form.addChild(_formItem);
                                  repeat = new CheckBox();
                                  repeat.label = "repeat";
                                  repeat.percentWidth= 100;
                                  _formItem.addChild(repeat);
  
                                  _formItem = new FormItem();
                                  _formItem.label = "Leads to";
                                  form.addChild(_formItem);
                          
                                  leadsTo = new ComboBox();
                                  leadsTo.width = 118;
                                  _formItem.addChild(leadsTo);
                          }
          
                  ]]>
          </mx:Script>
          <mx:StringValidator id="clipSourceValidator"
                  minLength="1"
                  property="text"
                   required="true"
                   tooShortError="The source is not a valid filename"
                   source="{this.source}"
          />
  
          <mx:Label y="-1" text="Clip Inspector" fontWeight="bold"/>
           <mx:Form id="form" y="20" width="100%" >
  
          <mx:FormItem label="Source" width="198">
                            <mx:TextInput id="source"  width="105"  />
                            <mx:LinkButton id="sourceButton" label="Browse" click="onSelectSource(event)"/>
          </mx:FormItem>
          <mx:FormItem width="198">        
                     <mx:CheckBox id="extra" label="Extra"  width="100%"  />
          </mx:FormItem>
          <mx:FormItem width="198">        
                     <mx:CheckBox id="repeat" label="Repeat"  width="100%" />
          </mx:FormItem>
           <mx:FormItem label="Leads to" width="198">
            <mx:ComboBox id="leadsTo" width="118" />
          </mx:FormItem>
      
      </mx:Form>
  
  </mx:Canvas>


(C) Æliens 18/6/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.