Sharp Mind

September 24, 2007

Add & Delete Components

Filed under: Flex — Kanu Wadhwa @ 5:00 am

AddDelCompo.mxml
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” xmlns=”*” layout=”horizontal” >
 <mx:Script>
  <![CDATA[
   import Note;
   import flash.events.Event;
   public function addNote(event:Event):void {
    var myNote:Note = new Note();
    myNote.x=event.target.x+50;
    myNote.y=event.target.y+50;
    myCanvas.addChild(myNote);
   }   
   public function deleteNote(note:Note):void {
    myCanvas.removeChild(note);
   }   
  ]]>
 </mx:Script>
 <mx:Model id=”myEmployee”>
  <employee employeeId=”5″>
   <firstName>John</firstName>
   <lastName>Smith</lastName>
   <phone>617-219-3345</phone>
  </employee>
 </mx:Model>
 <mx:HBox id=”myCanvas”>
  <mx:Panel id=”myPanel” width=”100%” height=”100%” click=”addNote(event)”>
   <mx:Label id=”empid” text=”{myEmployee.employee.employeeId}”/>
   <mx:Label id=”fname” text=”{myEmployee.employee.firstName}”/>
   <mx:Label id=”lname” text=”{myEmployee.employee.lastName}”/>
   <mx:Label id=”phone” text=”{myEmployee.employee.phone}”/>
  </mx:Panel>
 </mx:HBox>
</mx:Application>
 

Compo.mxml

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” xmlns=”*” backgroundColor=”yellow” width=”150″ borderStyle=”outset” height=”150″>
 <mx:Script>
 <![CDATA[
  import mx.core.Application;
  public function minSize():void {
   this.height=20;
   this.width=20;
  }
  public function maxSize():void {
   this.height=150;
   this.width=150;
  }
 ]]>
 </mx:Script>
 <mx:VBox>
  <mx:TextArea backgroundColor=”yellow” width=”100%” id=”myTextArea” click=”maxSize()”/>
  <mx:HBox>
   <mx:Button click=”Application.application.deleteNote(this)” label=”Delete”/>
   <mx:Button click=”minSize()” label=”Save” />
  </mx:HBox>
 </mx:VBox>
</mx:Canvas>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.