IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Flex Discussion :

drag and drop d'une list vers un tree


Sujet :

Flex

  1. #1
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Juillet 2010
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2010
    Messages : 30
    Points : 18
    Points
    18
    Par défaut drag and drop d'une list vers un tree
    Salut,

    Je voudrai faire un drag and drop depuis une liste vers un tree, j;ai trouver un exemple sur le net : http://blog.comtaste.com/upload/DragDropListTree.mxml

    Je l'ai adapter a mon code mais ca ne fonctionne pas.
    J'ai ce message d'erreur :
    TypeError: Error #1009: Cannot access a property or method of a null object reference
    Ca correspond a cette ligne dans mon code : "(tree.dataProvider as ArrayCollection).addItemAt(obj, index);"

    Voici le code complet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
     
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   xmlns:components="flexsamples.components.*"
                   xmlns:ext="nl.wv.extenders.panel.*"
                   creationComplete="showWindow();"  xmlns:ns1="*">
        <fx:Style source="styles/CollapsibleAccordionStyle.css"/>
        <fx:Script>
            <![CDATA[
                import flash.geom.Point;
     
                import mx.charts.ChartItem;
                import mx.charts.Legend;
                import mx.charts.PieChart;
                import mx.charts.chartClasses.ChartBase;
                import mx.charts.events.ChartItemEvent;
                import mx.charts.series.PieSeries;
                import mx.charts.series.items.ColumnSeriesItem;
                import mx.collections.ArrayCollection;
                import mx.collections.ArrayList;
                import mx.collections.ICollectionView;
                import mx.collections.XMLListCollection;
                import mx.containers.Canvas;
                import mx.containers.TitleWindow;
                import mx.controls.*;
                import mx.core.DragSource;
                import mx.core.IUIComponent;
                import mx.core.UIComponent;
                import mx.events.*;
                import mx.events.DragEvent;
                import mx.events.FlexEvent;
                import mx.managers.DragManager;
                import mx.managers.PopUpManager;
                import mx.rpc.events.*;
                import mx.utils.ArrayUtil;
     
                import nl.wv.extenders.panel.*;
     
                import spark.components.Panel;
                import spark.components.RichText;
                import spark.components.TitleWindow;
     
                [Bindable]public var usrs:ArrayCollection;
     
                public function showWindow():void {
                    var login:TitleExample=TitleExample(PopUpManager.createPopUp( 
                        this, TitleExample , true) as spark.components.TitleWindow); 
                    login.x=600;
                    login.y=200;
     
                    login.userType = returnName;
                }
     
                public function isAdmin():void
                {
                    services.getOperation('isAdmin').send(returnName.text);
                }
     
                public function isAdmin_true(evt:ResultEvent):void
                {
                    if (evt.result == 1)
                        currentState = 'adm';
                    else
                        currentState = 'normal';
                    getUsers();
                }
     
                public function onFault(event:FaultEvent):void
                {
                    Alert.show(event.fault.faultString, "Error !");
                }
     
                public function getUsers():void
                {
                    usr.getOperation('getUser').send();
                }
     
                public function rempliCombo(evt:ResultEvent):void
                {
                    usrs = new ArrayCollection(ArrayUtil.toArray(evt.result));
                }
     
                private function usrSelect(evt:Event):void
                {
                    slct.text = "You select " +  sel.selectedItem;
                }
     
                private function showPopUp():void
                {
                    currentState = 'popUp';
                }
     
                protected function handleClose(event:MouseEvent):void
                {
                    this.currentState="normal";
                }
     
                [Bindable]public var dateCollection:ArrayCollection;
     
                private function dataprov(evt:ResultEvent):void
                {
                    dateCollection = new ArrayCollection(ArrayUtil.toArray(evt.result));
                    vs.selectedChild = a1;
                }
     
                private function display(data:Object, field:String, index:Number, percentValue:Number):String
                {
                    var temp:String= (" " + percentValue).substr(0,6);
                    return data.keyword + ": " + '\n' + "Ponderation: " + data.ponderation + '\n' + temp + "%";
                }
     
                private function next():void
                {
                    if (vs.selectedChild == a2)
                        vs.selectedChild = a1;
                    else if(vs.selectedChild == a1)
                        vs.selectedChild = a2;
                }
     
                private function closed(e:MouseEvent):void
                {
                    PopUpManager.removePopUp(e.currentTarget as IUIComponent);
                }
     
                private var info:TitleExample;     
                private var key:List = new List();
                private function toto(e:MouseEvent):void
                {
                    info =TitleExample(PopUpManager.createPopUp( 
                        this, TitleExample , false) as spark.components.TitleWindow);     
                    var tab:Array = new Array();
                    var u:LinkButton = new LinkButton();
                    var dele:LinkButton = new LinkButton();
     
                    info.removeAllElements();
                    key.dragEnabled = true;
     
                    dele.label="supprimer cette infos";
                    dele.y = info.height - u.height - 10;
                    dele.x = info.width - dele.width - 10;
                    u.label = "Se rendre sur le site source";
                    u.y = info.height - u.height - 10;
                    u.x = 10;
     
                    for (var i:int = 0; i < series1.selectedItems.length; i++)
                    {
                        tab[0] = "Mots clef : " + dateCollection.getItemAt(series1.selectedIndices[i]).keyword;
                        tab[1] = "Description : " + dateCollection.getItemAt(series1.selectedIndices[i]).descr;
                        tab[2] = "Date de parution : " + dateCollection.getItemAt(series1.selectedIndices[i]).date;
                        tab[3] = "Lien : " + dateCollection.getItemAt(series1.selectedIndices[i]).lien;
                        key.dataProvider = tab;
                        u.data = dateCollection.getItemAt(series1.selectedIndices[i]).lien;
                    }
                    info.addElement(key);
                    info.addElement(u);
                    info.addElement(dele);
                    u.addEventListener(MouseEvent.CLICK, show);
                    dele.addEventListener(MouseEvent.CLICK, deleteInfo);
                }
     
                private function deleteInfo(e:MouseEvent):void
                {
                    PopUpManager.removePopUp(info);
                }
     
                private function show(e:MouseEvent):void
                {
                    var u:URLRequest = new URLRequest(e.currentTarget.data);
                    navigateToURL(u,"_blank");
                }
     
                private function initApp():void
                {
                    series1.addEventListener(MouseEvent.CLICK, toto);
                }
     
     
                /************************************************************/
     
                public function onTreeDragEnter(event:DragEvent):void
                {
                    event.preventDefault();
                    DragManager.acceptDragDrop(event.target as IUIComponent);
                    tree.showDropFeedback(event);
                }
     
                public function onTreeDragOver(event:DragEvent):void
                {
                    event.preventDefault();
                    tree.showDropFeedback(event);
                }
     
                public function onTreeDragExit(event:DragEvent):void
                {
                    event.preventDefault();
                    tree.hideDropFeedback(event);
                }    
     
                public function onTreeDragDrop(event:DragEvent):void
                {
                    event.preventDefault();
                    tree.hideDropFeedback(event);
                    var index:int = tree.calculateDropIndex(event);
     
                    var items:Array = new Array();
     
                    if(event.dragSource.hasFormat("treeItems"))
                        items = items.concat(event.dragSource.dataForFormat("treeItems") as Array);
     
                    if(event.dragSource.hasFormat("items"))
                        items = items.concat(event.dragSource.dataForFormat("items") as Array);
     
     
                    if(index > (tree.dataProvider as ICollectionView).length)
                        index = (tree.dataProvider as ICollectionView).length;
     
     
                    for each(var item:Object in items)
                    {
                        var obj:Object = new Object()
                        obj.label = "salut"; //chaine en dur pour le test
                        (tree.dataProvider as ArrayCollection).addItemAt(obj, index);
                    }
                }    
     
     
            ]]>
        </fx:Script>
     
        <fx:Declarations>
            <mx:RemoteObject id="services" destination="amfphp" source="isAdmin">
                <mx:method name="isAdmin" 
                           result="isAdmin_true(event)"
                           fault="onFault(event)"/>
            </mx:RemoteObject>
     
            <mx:RemoteObject id="usr" destination="amfphp" source="getUser">
                <mx:method name="getUser"
                           result="rempliCombo(event)"
                           fault="onFault(event)"/>
            </mx:RemoteObject>
     
            <mx:RemoteObject id="donnee" destination="amfphp" source="datap">
                <mx:method name="datap"
                           result="dataprov(event)"
                           fault="onFault(event)"/>
            </mx:RemoteObject>
     
            <s:ArrayList id="arr2">
                <!--<fx:String>Banana</fx:String>-->
            </s:ArrayList>
     
            <fx:Model id="listSample" source="sampledata/listsample.xml"/>
            <fx:XMLList id="treeData">
                <node label="Mail Box">
                    <node label="Inbox">
                        <node label="Marketing"/>
                        <node label="Product Management"/>
                        <node label="Personal"/>
                    </node>
                    <node label="Outbox">
                        <node label="Professional"/>
                        <node label="Personal"/>
                    </node>
                    <node label="Spam"/>
                    <node label="Sent"/>
                </node>    
            </fx:XMLList>
     
     
        </fx:Declarations>
     
        <s:transitions>
            <mx:Transition fromState="*" toState="*">
            </mx:Transition> 
        </s:transitions>
     
        <s:states>
            <s:State name="normal" />
            <s:State name="adm"/>
        </s:states>
     
        <s:BorderContainer id="reg"
                           backgroundColor="0x000000" color="0xFFFFFF" width="100%" height="100%" excludeFrom="adm">
            <mx:HBox height="100%" width="100%" horizontalGap="0">
     
                <components:CollapsibleAccordion id="collapsibleAccordion1" 
                                                 height="100%"
                                                 orientation="right"
                                                 barSize="36"
                                                 openSize="300"
                                                 currentWidth="360"
                                                 drawerButtonStyle="drawerButton"
                                                 closeButtonStyle="drawerCloseRight"
                                                 accordianStyle="drawerAccordion">
                    <mx:Canvas width="100%" height="100%" label="Online" icon="@Embed(source='assets/email-48x48.png')">
     
                    </mx:Canvas> 
                </components:CollapsibleAccordion>
     
                <mx:Panel title="Bienvenue" width="100%" height="100%" creationComplete="donnee.getOperation('datap').send();">
                    <mx:VBox paddingLeft="5" paddingTop="50" height="100%" width="100%">
                        <mx:HBox>
                            <s:RichText text="Bienvenue " />
                            <s:RichText id="returnName" text="" updateComplete="isAdmin();"/>
                        </mx:HBox>
     
                        <mx:ViewStack id="vs" width="100%" height="100%">
     
                        <s:NavigatorContent id="a1">
                        <mx:PieChart height="100%" width="100%" paddingRight="5" paddingLeft="5" color="0x323232"
                                 showDataTips="true" dataProvider="{dateCollection}">
     
                            <mx:series>
                                <mx:PieSeries id="dyn" labelPosition="callout" field="ponderation" labelFunction="display">
                                    <mx:calloutStroke>
                                        <s:SolidColorStroke weight="0" color="0x888888" alpha="1.0"/>
                                    </mx:calloutStroke>
                                    <mx:radialStroke>
                                        <s:SolidColorStroke weight="0" color="#FFFFFF" alpha="0.20"/>
                                    </mx:radialStroke>
                                    <mx:stroke>
                                        <s:SolidColorStroke color="0" alpha="0.20" weight="2"/>
                                    </mx:stroke>
                                </mx:PieSeries>
                            </mx:series>    
                        </mx:PieChart>
                        </s:NavigatorContent>
     
                        <s:NavigatorContent id="a2">
     
                            <mx:ColumnChart id="column" 
                                            height="100%" 
                                            width="100%" 
                                            showDataTips="true" 
                                            dataProvider="{dateCollection}" 
                                            selectionMode="single"
                                            creationComplete = "initApp()"                                        
                                            >
                                <mx:series>
                                    <mx:ColumnSeries id="series1" 
                                                     yField="ponderation" 
                                                     displayName="Ponderation" 
                                                     selectable="true"
                                                     /> 
                                </mx:series>            
                                <mx:horizontalAxis>
                                    <mx:CategoryAxis categoryField="date"/>
                                </mx:horizontalAxis>                        
                            </mx:ColumnChart>
                        </s:NavigatorContent>
     
                        </mx:ViewStack>
                        <mx:Button icon="@Embed(source='assets/closeleft.png')" click="next()"/>
                    </mx:VBox>
                </mx:Panel>
     
                <components:CollapsibleAccordion id="collapsibleAccordion3" 
                                                 height="100%"
                                                 orientation="left"
                                                 barSize="36"
                                                 currentWidth="36"
                                                 drawerButtonStyle="drawerButton"
                                                 closeButtonStyle="drawerCloseRight"
                                                 accordianStyle="drawerAccordion">
                    <mx:Canvas width="100%" height="100%" label="Dossier" icon="@Embed(source='assets/rss-48X48.png')">
     
                        <mx:VBox width="100%" height="100%">
                        <s:Panel id="garde" title="Je garde" color="0xffffff" borderAlpha="0.15" width="100%" height="50%">
                            <mx:List color="0x000000" width="100%" height="100%" dropEnabled="true" dragEnabled="true" dragMoveEnabled="true" />
                        </s:Panel>
     
                        <s:Panel id="del" title="Je jette" color="0xffffff" borderAlpha="0.15" width="100%" height="50%">
     
                            <mx:Tree id="tree" width="50%" labelField="@label" color="0x000000"
                                     showRoot="false" dataProvider="{treeData}"
                                     dragEnter="onTreeDragEnter(event)"
                                     dragOver="onTreeDragOver(event)"
                                     dragExit="onTreeDragExit(event)"
                                     dragDrop="onTreeDragDrop(event)"
                                     />
     
                        </s:Panel>
                        </mx:VBox>
                    </mx:Canvas>
                </components:CollapsibleAccordion>
     
            </mx:HBox>
        </s:BorderContainer>
     
        <s:BorderContainer id="re" includeIn="adm"
                           backgroundColor="0x000000" color="0xFFFFFF" cornerRadius="7" width="1024" height="600" horizontalCenter="-43" verticalCenter="77"> 
            <s:Label text="Bienvenue admin" paddingLeft="5" paddingTop="5"/>
            <s:HGroup paddingTop="30" paddingLeft="5">
                <s:Label text="Utilisateur a mettre a jour : "/>
                <s:VGroup>
                    <s:ComboBox id="sel" dataProvider="{usrs}" width="150" color="0x000000" change="usrSelect(event)" selectedIndex="0"/>
                    <s:Label id="slct"/>
                </s:VGroup>
            </s:HGroup>
        </s:BorderContainer>
    </s:Application>

  2. #2
    Membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Juillet 2008
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2008
    Messages : 55
    Points : 43
    Points
    43
    Par défaut
    Bonjour,

    je ne peux pas t'aider sur le problème, mais je te conseillerais de commencer plus facilement par le drag and drop.

    le tree et la list sont des composants qui intègrent le Drag and Drop de base (dragEnabled=true, dropEnabled=true, ...)

    J'ai commencé comme ça, puis en rajoutant des fonctionnalités petit à petit on comprend mieux.

    Bonne chance

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Août 2006
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2006
    Messages : 141
    Points : 118
    Points
    118
    Par défaut
    Il faudrait avoir toute les souces de ton projet pour pouvoir trouver vraiment le problème.

    mais à vue de nez, sans aucune certidude, je pencherais sur le fait que ton tree.dataProvider est null au moment ou tu appelles ta ligne de code. Il essaye donc de faire un addItem sur un objet null.

    ça peut être aussi ton tree qui n'est pas encore crée.
    Regarde en debug

  4. #4
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Juillet 2010
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2010
    Messages : 30
    Points : 18
    Points
    18
    Par défaut
    Merci de m'avoir répondu.

    Finalement j'ai fait plus simple, je drag and drop d'un tree vers un autre tree, comme ca pas de problèmes.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [WD17] Drag and Drop depuis une table vers un champ de saisie
    Par Dramon dans le forum WinDev
    Réponses: 0
    Dernier message: 24/02/2015, 16h36
  2. [WD14] Drag and drop de ma liste vers l'explorer
    Par law56100 dans le forum WinDev
    Réponses: 0
    Dernier message: 13/10/2009, 09h53
  3. Drag and drop sur une PictureBox
    Par abdiouldbody dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 17/06/2009, 15h55
  4. Drag and drop d'une structure avec virtualtreeview
    Par laudur dans le forum Composants VCL
    Réponses: 1
    Dernier message: 03/05/2006, 16h14
  5. [FLASH MX2004] Drag and drop entre deux List
    Par aldo-tlse dans le forum Flash
    Réponses: 15
    Dernier message: 24/09/2005, 01h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo