hello everyone,
I post onthe good forum, sorry for the previous one at Flash CS3 …
i ve a problem about my script that should show me entries of an xml file :
<?xml version="1.0" encoding="utf-8" ?>
<videos>
<video name="motion 01" genre="motion" data="thumbs/motion01.jpg" />
<video name="motion 02" genre="abstrait" data="thumbs/motion02.jpg" />
<video name="motion 03" genre="art video" data="thumbs/motion03.jpg" />
<video name="motion 04" genre="motion" data="thumbs/motion04.jpg" />
<video name="motion 05" genre="abstrait" data="thumbs/motion05.jpg" />
<video name="motion 06" genre="art video" data="thumbs/motion06.jpg" />
<video name="motion 07" genre="motion" data="thumbs/motion07.jpg" />
</videos>
inside a dataGrid (myDataP1) versus their attributes “genre”.
the loading in the dataGrid is ok, when i click to btSort with that script it’s ok
function monTri(evt:Event):void {
//myXML = new XML(evt.target.data);
var myDP = new DataProvider(myXML);
myDP.sortOn("genre");// classe les genres
if (myXML.video.(@genre=="motion")) {
for (var i:uint = 0; i < myDP.length; i++) {
myDP.removeItemAt(myXML.video.(@genre!=="motion"));
}
myDataP1.dataProvider = myDP;
}
}
btSort.addEventListener(MouseEvent.CLICK, monTri);
the problem happen when i want to click on a second button that should change entries of dataP1 with another @genre …
function monTri2(evt:Event):void {
//myXML = new XML(evt.target.data);
var myDP = new DataProvider(myXML);
myDP.sortOn("genre");
if (myXML.video.(@genre!=="abstrait")) {
for (var i:uint = 0; i < myDP.length; i++) {
myDP.removeItemAt(myXML.video.(@genre!=="abstrait"));
}
myDataP1.dataProvider = myDP;
}
}
btSort2.addEventListener(MouseEvent.CLICK, monTri2);
i m trying an other kind of script but this one can not remove Item that have !=motion …
function monTri3(evt:Event) {
var myDP = new DataProvider(myXML);
var myStyle:String = "motion";
for (var i:Number=0; i < myDP.length; i++) {
var item:XML = XML(myDP.getItemAt(i));
trace(item);
if (item.@genre !== myStyle) {
myDP.removeItemAt(i);
}
}
myDataP1.dataProvider = myDP;
}
btSort2.addEventListener(MouseEvent.CLICK, monTri2);
the last oner should work but it s not … if anyone as an idea of what’s going on it will be very helpfull.
Thanks you.
DisplayLists are shifting when u remove something from middle
thank you for answering.
as im looking for items with attributes i thought it was not important.i there any other way to have only xml entries that i want when i click on my button ? let’s say having an array , removing item from this array and then adding data to my dataGrid; that’s what i would do in as2, but in as3 it s a little bit more confused for me.
var myDP = new DataProvider(myXML); // so my DP is myArray
var myStyle:String = "motion";
for (var i:Number=0; i < myDP.length; i++) {
var item:XML = XML(myDP.getItemAt(i));// i "tooking" all items of myData
trace(item);
if (item.@genre !== myStyle) { // if some of these items genre attribute =="motion"
myDP.removeItemAt(i);// delete these items
}
}
myDataP1.dataProvider = myDP;// write inside of myDataGrid
may you help me to understand how to do that ?
maybe that
var myDP = new DataProvider(myXML);
var myStyle:String = "motion";
for (var i:Number=0; i < myDP.length; i++) {
var item:Object=myDP.getItemAt(i);
if (item.genre != myStyle) {
myDP.removeItemAt(i);
}
}
myDataP1.dataProvider = myDP;
[quote=Felixz;2326285]maybe that ActionScript Code:
[LEFT][COLOR=#000000]var[/COLOR] myDP = [COLOR=#000000]new[/COLOR] DataProviderCOLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] myStyle:[COLOR=#0000FF]String[/COLOR] = [COLOR=#FF0000]“motion”[/COLOR];
[COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]var[/COLOR] i:[COLOR=#0000FF]Number[/COLOR]=[COLOR=#000080]0[/COLOR]; i < myDP.[COLOR=#0000FF]length[/COLOR]; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#000000]var[/COLOR] item:[COLOR=#0000FF]Object[/COLOR]=myDP.[COLOR=#000080]getItemAt[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]item.[COLOR=#000080]genre[/COLOR] != myStyle[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
myDP.[COLOR=#000080]removeItemAt[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
myDataP1.[COLOR=#000080]dataProvider[/COLOR] = myDP;
[/LEFT]
[/quote] thanks a lot to help me … this doesn’t work but helped me to understand that in fact the removeItem stop as soon as it found the first item ==“motion”, it s like if the loop stop.
Heres is my fullscript:
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
import fl.events.*;
import flash.xml.*;
import flash.media.Video;
import fl.controls.ComboBox;
var myList:XMLList;
var myXML:XML = new XML();
function parseXML():void {
var url:String = "myData2.xml";
var urlRequest:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.addEventListener("complete" , creaListe);
loader.load(urlRequest);
}
parseXML();
function creaListe(evt:Event):void {
myXML = new XML(evt.target.data);
myDP = new DataProvider(myXML);
trace(myDP);
myDP.sortOn("genre");
//myDP.sortOn("genre", Array.DESCENDING);
myDataP1.dataProvider = myDP;
// Definition des colonnes du DataGrid
var dateCol:DataGridColumn = new DataGridColumn("name");
dateCol.headerText = "Nom";
dateCol.width = 90;
var genreCol:DataGridColumn = new DataGridColumn("genre");
genreCol.headerText = "Genre";
genreCol.width = 90;
var myDP:DataProvider;
myDataP1.columns = [dateCol, genreCol];// DataGrid column Array
myDataP1.dataProvider = myDP;
myDataP1.rowCount = myDataP1.length;
myDataP1.setSize(250, 240);
}
var loader:Loader = new Loader();
loader.x = 350;
loader.y = 200;
addChild(loader);
function monTri3(evt:Event) {
var myDP = new DataProvider(myXML);
myDP.sortOn("genre");
var myStyle:String = "motion";
for (var i:Number=0; i < myDP.length; i++) {
var item:Object=myDP.getItemAt(i);
trace("i= "+i);
if (item.genre != myStyle) {
trace("item != myStyle >>"+item);
myDP.removeItemAt(i);
}
trace("item from list >>"+item);
myDataP1.dataProvider = myDP
}
}
btSort3.addEventListener(MouseEvent.CLICK, monTri3);
i use this xml (“myData2.xml”):
<?xml version="1.0" encoding="utf-8" ?>
<videos>
<video name="anim 01" genre="motion" data="thumbs/anim01.jpg"/>
<video name="anim 02" genre="abstrait" data="thumbs/anim02.jpg"/>
<video name="anim 03" genre="art video" data="thumbs/anim03.jpg"/>
<video name="anim 04" genre="motion" data="thumbs/anim04.jpg"/>
<video name="anim 05" genre="abstrait" data="thumbs/anim05.jpg"/>
<video name="anim 06" genre="danse" data="thumbs/anim06.jpg"/>
<video name="anim 07" genre="sport" data="thumbs/anim07.jpg"/>
</videos>
when i publish , the output window give me :
DataProvider [[object Object] , [object Object] , [object Object] , [object Object] , [object Object] , [object Object] , [object Object]]
i= 0
item != myStyle >>[object Object]
item from list >>[object Object]
i= 1
item != myStyle >>[object Object]
item from list >>[object Object]
i= 2
item from list >>[object Object]
i= 3
item from list >>[object Object]
i= 4
item != myStyle >>[object Object]
item from list >>[object Object]
////
as i you can see “i” stop to 4 but there is 7 entries in myDP, that is the value of the fifth element (the first item with motion item attribute). I wonder if there is a way to go above (i’m realy sorry for my english :crying:)