# Accordian Help/maybe use a dataset?

**URL:** https://forum.kirupa.com/t/accordian-help-maybe-use-a-dataset/295007
**Category:** Uncategorized
**Created:** [August 24, 2009, 10:27am UTC](https://forum.kirupa.com/t/accordian-help-maybe-use-a-dataset/295007 "2009-08-24T10:27:01Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![TonyL](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@TonyL](https://forum.kirupa.com/u/TonyL)
#### Post date: [August 24, 2009, 10:27am UTC](https://forum.kirupa.com/t/accordian-help-maybe-use-a-dataset/295007/1 "2009-08-24T10:27:01Z")

</div>

Hi all.

I have an Accordian component with 2 children hard coded in, I dynamically load create children into these accodians children to have a 2 level accordian. I also have need to destry the children via a delete button on each individual one. Everything works fine, until, I destroy a child.

After destroying a child and trying to add the next child another child is removed and I then get a gap in between items (I do loop through the accordian and use the Move method to ensure each child is in the correct position)

I can’t figure this one out. Anyone got any ideas?

My code is as follows:

```auto

[FONT=Courier New]function AddToTearOffs(WinID,SName,CName){[/FONT]
 
[FONT=Courier New] var child_obj:Object = _root.GadgetBar.myTearOffs.myTearOffsAcc.getChildAt(0);[/FONT]
[FONT=Courier New] var curSubjects:Number = child_obj.numChildren;[/FONT]
[FONT=Courier New] var Present:Boolean = false;[/FONT]
 
[FONT=Courier New] trace(curSubjects);[/FONT]
 
[FONT=Courier New] for (i=0; i<curSubjects; i++) {[/FONT]
[FONT=Courier New] child_obj.getChildAt(i).move(0,i*20);[/FONT]
[FONT=Courier New] if (child_obj.getChildAt(i).ButtonText.Text.text == CName){[/FONT]
[FONT=Courier New] Present = true;[/FONT]
[FONT=Courier New] }[/FONT]
[FONT=Courier New] };[/FONT]
 
[FONT=Courier New] if (Present == false){[/FONT]
[FONT=Courier New] var TearOffItem:Object = child_obj.createChild("TearOffItem", ["SubjectLbl"+WinID], {_x:0, _y:curSubjects*20});[/FONT]
[FONT=Courier New] TearOffItem.ButtonText.Text.text = CName;[/FONT]
 
 
[FONT=Courier New] TearOffItem.DeleteTearOff.onRelease = function(){[/FONT]
 
[FONT=Courier New] var child_obj:Object = _root.GadgetBar.myTearOffs.myTearOffsAcc.getChildAt(0);[/FONT]
[FONT=Courier New] var curSubjects:Number = child_obj.numChildren;[/FONT]
[FONT=Courier New] for (i=0; i<curSubjects; i++) {[/FONT]
 
[FONT=Courier New] if (child_obj.getChildAt(i).ButtonText.Text.text == CName){[/FONT]
[FONT=Courier New] child_obj.destroyChildAt(i);[/FONT]
[FONT=Courier New] updateAfterEvent();[/FONT]
[FONT=Courier New] }[/FONT]
 
[FONT=Courier New] var WindowX:Tween = new Tween(child_obj.getChildAt(i), "_y", Strong.easeInOut, child_obj.getChildAt(i)._y, i*20, .5, true); [/FONT]
[FONT=Courier New] child_obj.getChildAt(i).move(0,i*20);[/FONT]
[FONT=Courier New] }; [/FONT]
 
[FONT=Courier New] } [/FONT]
 
[FONT=Courier New] }[/FONT]
 
 
[FONT=Courier New]}[/FONT]

```

I have considered trying to use a dataset to manage this and firing the dataset into a SharedObject. But, I can’t seem to cretae the Dataset in flash? Is it possible to create and use a dataset entirely in flash without being loaded from an external source?

My code so far is a as follows:

```auto

function CreateDS(WinID,SName,CName){
var my_ds:DataSet;
// Load Existing Dataset
try {
    my_ds.loadFromSharedObj("DSTearOffs");
} catch(e:DataSetError) {
    trace("Unable to load shared object."); 
}
 
// Apend Dataset with new Item
//my_ds.createItem({WinID:WinID, SName:SName, CName:CName});
my_ds.addItem(my_ds.createItem({WinID:"A", SName:"B", CName:"C"}));
 
// Save New Dataset
try {
    my_ds.saveToSharedObj("DSTearOffs");
} catch(e:DataSetError) {
    trace("Unable to create shared object"); 
}
};

```

I appriciate this is a long post with many questions, but, any help gretaly appriciated!

Thanks, TonyL
