Renderers get recycled.  This means that creationComplete gets called once, but 
the data property changes many times.  The sound being played should be bound 
from the data property.

Read up on renderers and see the articles on my blog (blogs.adobe.com)

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of 
mousikos2001
Sent: Monday, March 03, 2008 10:27 AM
To: [email protected]
Subject: [flexcoders] DataGrid Custom Component problem

Hello all

I have this problem. I have a datagrid with many rows, actually 720.
in the datagrid i use a custom component i've made which plays an mp3
file taken from the xml file which populates the datagrid.

The problem is that when i scroll up or down the datagrid the mp3s get
mixed up as a result if you click the first row mp3 to play and then
after a scroll or two you click it again you hear a different mp3
playing...

here is the code...



<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" creationComplete="decisionList.send();"
xmlns:view="view.*">

     <mx:Script>
         <![CDATA[

             import mx.controls.Alert;
             import view.soundPlay;

             [Bindable]
             public var decisionXML:XML;


             private function resultHandler():void
             {
                 decisionXML = decisionList.lastResult as XML;
             }

             public function getDetails(id:Number,rating:Number):void {
                 Alert.show('hello '+id+" "+rating);
             }

         ]]>
     </mx:Script>

     <mx:HTTPService id="decisionList" resultFormat="e4x"
url="mp3results.xml" result="resultHandler()"/>

     <mx:HTTPService id="sendRating" url="rating.php" />

     <mx:Panel width="770" height="500" layout="absolute" x="61" y="23">
         <mx:DataGrid id="decisionDataGrid"
                      editable="true" textAlign="center"
                      draggableColumns="false"
                      resizableColumns="false"
                      sortableColumns="false"
                      selectable="true"
                      dataProvider="{decisionXML.example}" left="10"
right="10" bottom="76" height="262">
             <mx:columns>
                 <mx:Array>
                           <mx:DataGridColumn dataField="id"
editable="false" headerText="A/A" width="100"/>

                           <mx:DataGridColumn dataField="samplepath"
editable="false" headerText="ΞʽΟ…ΞΈΞΌΟŒΟ‚">
                           <mx:itemRenderer>
                               <mx:Component>
                                   <view:soundPlay
soundUrl="MP3{data.samplepath}" />
                               </mx:Component>
                           </mx:itemRenderer>
                           </mx:DataGridColumn>

                           <mx:DataGridColumn dataField="childreaction"
editable="false" headerText="Ξ‘Ο€ΟŒΞΊΟΞΉΟƒΞ·">
                           <mx:itemRenderer>
                               <mx:Component>
                                   <view:soundPlay
soundUrl="{data.childreaction}" />
                               </mx:Component>
                           </mx:itemRenderer>
                           </mx:DataGridColumn>

                           <mx:DataGridColumn dataField="rate"
                                              width="100"
textAlign="center"
                                             
headerText="Βαθμολογία"
                                              sortable="false"
                                              rendererIsEditor="true"
                                              editorDataField="value">
                               <mx:itemRenderer>
                               <mx:Component>
                                   <mx:HBox horizontalAlign="center">
                                       <mx:Script>
                                           <![CDATA[
                                               [Bindable]
                                               public var value:Number;
                                           ]]>
                                       </mx:Script>
                                       <mx:NumericStepper
id="displayNumberStepper" value="{data.rate}" change="value =
displayNumberStepper.value"/>
                                   </mx:HBox>
                               </mx:Component>
                               </mx:itemRenderer>
                           </mx:DataGridColumn>
                           <mx:DataGridColumn
                                        width="120" textAlign="center"
                                       
headerText="ΑποστολΞ βαθμολογίας"
                                         editable="false"
                                         >
                         <mx:itemRenderer>
                             <mx:Component>
                                 <mx:HBox horizontalAlign="center">

                                   <mx:Button
label="ΑποστολΞ"
click="outerDocument.getDetails(data.id,data.rate)"  />
                                 </mx:HBox>
                             </mx:Component>
                         </mx:itemRenderer>
                     </mx:DataGridColumn>

                 </mx:Array>
             </mx:columns>
         </mx:DataGrid>


     </mx:Panel>
</mx:Application>

And here is the component's code

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";
xmlns:net="flash.net.*" xmlns:media="flash.media.*" width="120"
height="44" creationComplete="mySound.load(myURLReq)">
<mx:Script>
     <![CDATA[
         [Bindable]
         public var soundUrl:String;
     ]]>
</mx:Script>

   <net:URLRequest id="myURLReq" url="{soundUrl}" />
   <media:SoundChannel id="mySoundChannel" />
   <media:Sound id="mySound"  />
   <mx:Button id="play" label="ΑναπαραγωγΞ"
click="mySoundChannel = mySound.play(0, 0, null);" horizontalCenter="0"
verticalCenter="0"/>
</mx:Canvas>




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links



Reply via email to