How to swap the position of two objects?

I have four self made componensts that I imported them into my main mxml file
and placed each on four corners.
What I want to achieve is to drag each component onto others then swap their position.
For example, comp A is dragged over comp B, when this is detected, swap the position of A and B.
But at the moment it doesn't seem to work properly. I could not figure out what's wrong with my code. Could any one help me achieve that?
Many thanks to any who could give me a hand!
*********This is one of my component***********
*********All other three components are made the same way, except each source of image file is different******************
<?xml version="1.0" encoding="utf-8"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" width="42" height="42">
    <mx:Image source="Images/air.png"/>
</mx:Box>
*********This is my mxml that calls my components***********
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:comp="Comp.*" creationComplete = "onInit()">
    <mx:Script>
        <![CDATA[
            import mx.containers.Box;
            import Comp.Icon_illustrator;
            import Comp.Icon_air;
            import Comp.Icon_flash;
            import Comp.Icon_flex;
            private var i_1:Icon_air; //1
            private var i_2:Icon_flash; //2
            private var i_3:Icon_flex; //3
            private var i_4:Icon_illustrator; //4
            private var origX:Number;
            private var origY:Number;
            private var startObj:String;
            private var icons:Array;
            private var h_1:Box;
            private var h_2:Box;
            private var h_3:Box;
            private var h_4:Box;
            private function onInit():void{
                //initialise all icons
                i_1 = new Icon_air();
                i_2 = new Icon_flash();
                i_3 = new Icon_flex();
                i_4 = new Icon_illustrator();
                i_1.name = "i_1";
                i_2.name = "i_2";
                i_3.name = "i_3";
                i_4.name = "i_4";
                //populate icon
                showArea.addChild(i_1);
                showArea.addChild(i_2);
                showArea.addChild(i_3);
                showArea.addChild(i_4);
                //set x position
                i_1.x = 100;
                i_2.x = 200;
                i_3.x = 100;
                i_4.x = 0;
                //set y position
                i_1.y = 0;
                i_2.y = 100;
                i_3.y = 200;
                i_4.y = 100;
                icons = [i_1, i_2, i_3, i_4];
                //addEventListeners
                for(var i:int=0; i<icons.length; i++){
                    icons[i].addEventListener(MouseEvent.MOUSE_DOWN, moveMe);
                    icons[i].addEventListener(MouseEvent.MOUSE_UP, stopDragMe);
            }//end of onInit
            private function moveMe(e:MouseEvent):void{
                e.currentTarget.startDrag();   
                showArea.setChildIndex(DisplayObject(e.currentTarget), 0);
                origX = e.currentTarget.x;
                origY = e.currentTarget.y;
                startObj = e.currentTarget.name;   
            private function stopDragMe(e:MouseEvent):void{
                if(this[startObj].hitTestObject(icons[1])){
                    trace("hit 2");
                    this[startObj].x = i_2.x;
                    this[startObj].y = i_2.y;
                    i_2.x = origX;
                    i_2.y = origY;
                }else if(this[startObj].hitTestObject(icons[0])){
                    trace("hit 1");
                    this[startObj].x = i_1.x;
                    this[startObj].y = i_1.y;
                    i_1.x = origX;
                    i_1.y = origY;
                }else{
                    trace("hit others");
                    this[startObj].x = origX;
                    this[startObj].y = origY;
                e.currentTarget.stopDrag();
            }//end of stopDragMe
        ]]>
    </mx:Script>
    <mx:Panel id="showArea" width="400" height="300" layout="absolute" backgroundColor="0x999999"/>
</mx:WindowedApplication>

Here is a sample of swaping two objects in Flex (not Air)   I believe it is the same.  Take a look at the way the x and y coords are swapped using the dragInitator and the currentTarget object in the dragDropHandler.
Hope this helps
<?xml version="1.0" encoding="utf-8"?><mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
 <mx:Script>
<![CDATA[
 import mx.containers.Box; 
import mx.core.UIComponent; 
import mx.managers.DragManager; 
import mx.core.DragSource; 
import mx.events.DragEvent; 
private var dragProxy:Box= new Box(); 
public function dragDropHandler(e:DragEvent): void { 
//These variables are the x and y coords of the objects 
//the e.dragInitator is the object being dragged 
//the e.currentTarget is the object being dropped on 
//First save the x and y coords of each of the objects 
var xdi:int = e.dragInitiator.x; 
var ydi:int = e.dragInitiator.y; 
var xct:int = e.currentTarget.x; 
var yct:int = e.currentTarget.y; 
//now switch them around.e.dragInitiator.x = xct;
e.dragInitiator.y = yct;
e.currentTarget.x = xdi;
e.currentTarget.y = ydi;
public function dragEnterHandler(event:DragEvent):void { 
DragManager.acceptDragDrop(UIComponent(event.target));
public function mouseMoveHandler(event:MouseEvent):void { 
if(event.buttonDown == false) return; 
var dragInitiator:UIComponent = event.target as UIComponent; 
var dragSource:DragSource = new DragSource(); 
dragProxy =
new Box();dragProxy.width = dragInitiator.width;
dragProxy.height = dragInitiator.height;
dragProxy.setStyle(
"borderStyle","solid")dragProxy.setStyle(
"borderColor","0x000000")dragProxy.setStyle(
"backgroundColor","0xc6c6c6"); 
DragManager.doDrag(dragInitiator, dragSource, event, dragProxy,
event.localX * -1, event.localY * -1, 1.00);
]]>
</mx:Script>
 <mx:Canvas width="84" height="93" x="23" y="14" borderStyle="
solid" borderColor="
#030303" backgroundColor="
#F83C3C"dragEnter="dragEnterHandler(event)"
dragDrop="dragDropHandler(event)"
mouseMove="mouseMoveHandler(event)"
>
 </mx:Canvas>
 <mx:Canvas width="84" height="93" x="223" y="14" borderStyle="
solid" borderColor="
#030303" backgroundColor="
#C5F83C"dragEnter="dragEnterHandler(event)"
dragDrop="dragDropHandler(event)"
mouseMove="mouseMoveHandler(event)"
>
 </mx:Canvas>
 </mx:Application>

Similar Messages

  • MBO - How to switch the position of two pushbuttons ?

    Hello Everyone,
    Please, may someone help me on this question:
    In the "Status Flow" Datasheet I specified 3 pushbuttons for a status. The previous Status and Subsequent Status were correctly configured in OOHAP_BASIC. However I did not find where I can configure the position of these pusbuttons when they are displayed on frontend or backend.
    For example I would like to switch 2 pushbuttons:
    | button 1 |     | button 2 |           =>      | button 2 |     | button 1 | 
    How can I do that ? Is there a configuration table ? Shall I use a specific Badi ?
    Thanks in advance for your answers.

    >
    JONATHAN DEPRAETERE wrote:
    > Thanks Michael for your express answer.
    >
    > Actually, I had already tested that solution ... and so I had changed the sequence of my pushbuttons during creation. However I noticed a strange behaviour during the activation. Indeed, even if I modify the sequence, after activation, the pushbuttons sequence comes back to the initial sequence.
    >
    > This behaviour is visible directly in the datasheet "Status Flow" and so in the backend and frontend display.
    >
    > Do you have an Idea, what would the root cause be ?
    >
    > Thanks in advance.
    interesting, maybe my original understanding was wrong than.... another try would be that it is sorting the pushbuttons in the status flow tab, based on the column ID.
    in tcode - oohap_basic - try switching the sequence of the push buttons based on their pusbutton ID. 
    than recreate the pushbuttons on the status flow tab...
    if it's not that, than I am thinking it just arranges itself automatically in the status flow tab based on what the pushbutton does (moves it a previous status vs a future status) - i doubt it is that smart though...

  • How to get the distance between two object!!!

    I have two GEOM object and want to know the distance between them, may u give me some solution to find the distance between them.

    Hi!,
    SDO_GEOM.SDO_DISTANCE
    see: http://www.oracle.com/technology/documentation/spatial.html
    regards, Andreas

  • How to fix the positions of two Mail.app viewer windows on the screen?

    I use Mail.app as my main IMAP Mail application. I work with two Mail viewer windows which I position on the screen so that the upper window shows the Inbox and the lower window the Send-box. The windows are aligned to each other and do not overlap. Fine.
    But when I quit Mail.app and open the program again, the windows have forgotten their postions. They "jump" to a new location on the screen. This is in contrast to all other applications I use. Another bad example of window managment is the Mail.app-Preferences window which also does not stick to a given position.
    Is this a (known?) bug or does it only happen on my Macs? (two: one in the office, one at home, both running 10.4.6)

    I guess the difference is that my description text is longer.
    Try this text for a new rule:
    "From: blacklisted senders 1 - move to SPAM-blacklisted-addresses"
    When you want to see this text completely with the default font, you will need to enlarge the Preferences window for "Rules". After that, click to "Signatures": the window stays at the enlarged width. Then click on any of the other areas in Preferences, and the window goes back to the "normal" width. When you then click on either "Signatures" or "Rules", the Preferences window will stay at the "normal" width (resulting in a truncated display of the rule description text).
    Also: when you have moved the Preferences window to a position not covered by a (large) viewer window to access it with a mouse click, close the window and re-open Preferences, it is back to a position covered by the viewer window. Again not accessible when the viewer window is the front-most Mail.app window. BTW: the "Activity viewer" window does a better job in sticking to a fix position.

  • How to get the intersection of two arraylist containing user defined obj??

    How to get the intersection of two arraylist containing user defined obj??
    I can easily get the intersection of two array list which containing some simple class(Integer, String). But how to get the intersection of two arrayList which contain user defined object?
    Here is the sample code..I can not run this out...anybody can help me? thank you very much..
    The correct result should be like this:
    2
    2
    but I can only get this:
    2
    0
    import java.util.*;
    public class testRetain{
         public static void main(String[] args){
              ArrayList a = new ArrayList();
              ArrayList b = new ArrayList();
              a.add( new dog(1,2,2) );
              a.add( new dog(1,2,1) );
    System.out.println(a.size() );
              b.add( new dog(1,2,2) );
              a.retainAll(b);
    System.out.println(a.size() );
    class dog implements Comparable{     
         int head;
         int arms;
         int legs;
         dog(int head, int arms, int legs){
              this.head = head;
              this.arms = arms;
              this.legs = legs;
         public int compareTo(Object o){
              if ( ((dog)o).head > this.head )
                   return -1;
              else if ( ((dog)o).head < this.head )
                   return 1;
              else
                   return 0;
    }

    @Op. Your classes should override equals and hashCode
    Kaj

  • Did you know how to link the text in two or more text boxes?

    Did anyone know how to link the text in two or more text boxes in Pages 5.0? Thanks for your answer.
    Qualcuno sa come collegare il testo in due o più caselle di testo nella versione 5.0 di Pages. Grazie per le vostre risposte.

    It's just one of the many, many features that have been eliminated or changed. Leave feedback for the Pages team using the link in the Pages menu and review & rate the new versions in the Mac App Store.
    If you previously had iWork '09, those apps are still in your Applications folder in a folder named iWork '09. You can continue to use them to get things done.

  • In BADi , How to pass the values between two Method

    Hi Experts,
    We have two methods in BADis. How to pass the value  between two Methods. Can you guys explain me out with one example...
    Thanks & Regards,
    Sivakumar S

    Hi Sivakumar!
    Create a function group.
    Define global data (there is a similiar menu point to jump to the top include).
    Create one or two function modules, with which you can read and write the global data.
    In your BADI methods you can access the global data with help of your function modules. It will stay in memory through the whole transaction.
    Regards,
    Christian

  • How to change the title of an object in the build order window?

    In Keynote '09 v5.1.1 (1034)... How to change the title of an object in the build order window from the default "dropped image" to a specific title?
    I'm running the following:
      Model Name: MacBook Pro
      Model Identifier: MacBookPro2,1
      Processor Name: Intel Core 2 Duo
      Processor Speed: 2.33 GHz
      Number Of Processors: 1
      Total Number Of Cores: 2
      L2 Cache: 4 MB
      Memory: 2 GB
      Bus Speed: 667 MHz
      Boot ROM Version: MBP21.00A5.B08
      SMC Version (system): 1.14f5

    Custom names can't be applied to objects in the build list.
    They are labeled as either; text, shape, table, chart or the filename of an image

  • How to get the difference of two dates in years,months and days

    Hi friends,
    how to get the difference of two dates in years,months and days
    for ex 2 years 3 months 13 days
    select (sysdate-date_Start) from per_periods_of_service
    thanks

    Something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date
      7        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      8        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
      9        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
    10* from t
    SQL> /
    C_START_D C_END_DAT        YRS      MNTHS        DYS
    17-NOV-06 21-JAN-08          1          2          4
    21-NOV-06 17-FEB-08          1          2         27
    21-JUN-06 17-JUL-08          2          0         26
    SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too.

  • HELP!! How to get the position of active windows in the desktop

    How to get the position of active windows in the desktop

    You mean, active windows other than the program you're running, or windows the program puts there? And a real desktop (like where MyComputer is), or a desktop pane?

  • How to change the position of a window created in the script?

    Hello to all
    A window called from another window are the same size. How can change the position of the window relative to the caller call window?

    That is worked, but for abs.coord. How make releative coord.?
    When I include that in my script, window show without elements ! See attachments №2

  • How to measure the size of an object written by myself?

    Hi all,
    I'm going to measure the performance on throughput of an ad hoc wireless network that is set up for my project. I wrote a java class that represents a particular data. In order to calculate the throughput, I'm going to send this data objects from one node to another one in the network for a certain time. But I've got a problem with it- How to measure the size of an object that was written by myself in byte or bit in Java? Please help me with it. Thank you very much.

    LindaL22 wrote:
    wrote a java class that represents a particular data. In order to calculate the throughput, I'm going to send this data "a data" doesn't exist. So there's nothing to measure.
    objects from one node to another one in the network for a certain time. But I've got a problem with it- How to measure the size of an object that was written by myself in byte or bit in Java? Not.

  • How to view the physical size of objects

    Hi
    Please advise how to view the physical size of objects like tables, indexes, materialize views etc.
    Wishes
    Jawad

    To see the physical size of objects like tables, indexes, use
    USER_SEGMENTS where SEGMENT_TYPE=table/index/partition etc.
    But for views/packages/java/trigger, you can only see rough estimate in USER_OBJECT_SIZE

  • How to check the owner of any Object in the database.

    How to check the owner of any Object in the database.
    Thanks
    Himanshu

    What about this ?
    SELECT owner,Object_name,object_type FROM all_objects
    OR
    SELECT owner,Object_name,object_type FROM dba_objects

  • How to make the attribute of type object private

    Hi All!
    How to make the attributes of type object private ?
    regards
    Sanjeeb Bose
    Kolkata India

    Sanjeeb,
    Object encapsulation can be enforced at your client/mid-tier API level (e.g., Java, C++).
    Regards,
    Geoff
    Hi All!
    How to make the attributes of type object private ?
    regards
    Sanjeeb Bose
    Kolkata India

Maybe you are looking for