PDA

View Full Version : onlastframe event


ch_bowen
10-25-2004, 09:55 AM
I am loading and playing an mp3 when a user clicks a 'play' button. I have a class that manages which buttons should be shown depending when the resource (mp3) is loaded. It seems that when the mp3 is initially loaded and played, View.onlastframe() event is not called and I need this event to re-initialize the state of the buttons. I have a flag that is set if the mp3 is already loaded and if it is, the second time around it plays alright and I get the 'onlastframe' event. When it is initially loaded and after it is done playing, I do not get the 'onlastframe' callback. The code is below if anyone can help me out. Thanks.

<library>
<include href="../resources.lzx"/>

<class name='playButtonManager' datapath=''>
<attribute name='mp3Cached' value='false'/>

<method name='reset'>
this.mp3Cached = false;
this.mp3Resource.stop();
this.mp3Resource.unload();
this.audioPlayButton.setAttribute('visible', true);
this.audioPlayButton.setAttribute('enabled', false);
this.loadingView.setAttribute('visible', false);
this.audioStopButton.setAttribute('visible', false);

var url = this.datapath.xpathQuery('@audio');
if(url == null || url == ''){
this.audioPlayButton.setAttribute('enabled', false);
}else{
this.audioPlayButton.setAttribute('enabled', true);
}
</method>

<method event='ondata'>
debug.write('ondata called');
reset();
</method>

<view name='mp3Resource' visible='false'>
<method event='onlastframe'>
classroot.audioPlayButton.setAttribute('visible', true);
classroot.loadingView.setAttribute('visible', false);
classroot.audioStopButton.setAttribute('visible', false);
this.setResourceNumber(1);
</method>
<method event='onload'>
this.play();
classroot.mp3Cached = true;
classroot.loadingView.setAttribute('visible', false);
classroot.audioStopButton.setAttribute('visible', true);
</method>
<method event='onerror'>
classroot.loadingView.setAttribute('visible', false);
classroot.audioPlayButton.setAttribute('enabled', false);
classroot.audioPlayButton.setAttribute('visible', true);
</method>

</view>

<basebutton name='audioPlayButton' resource='audioButtonPlayResource' visible='true'>
<method event='onclick'>
<![CDATA[
if(classroot.mp3Cached){
classroot.mp3Resource.setResourceNumber(1);
classroot.mp3Resource.play();
this.setAttribute('visible',false);
classroot.audioStopButton.setAttribute('visible', true);
}else{
var url = classroot.datapath.xpathQuery('@audio');
this.setAttribute('visible', false);
classroot.loadingView.setAttribute('visible', true);
classroot.mp3Resource.setSource(url);
}
]]>
</method>
</basebutton>

<view name='loadingView' resource='audioLoadingImage' visible='false'/>

<basebutton name='audioStopButton' resource='audioButtonStopResource' visible='false'>
<method event='onclick'>
<![CDATA[
classroot.mp3Resource.stop();
this.setAttribute('visible', false);
classroot.audioPlayButton.setAttribute('visible', true);
]]>
</method>
</basebutton>
</class>
</library>

ch_bowen
10-27-2004, 03:08 AM
Anyone have any suggestions or have experienced similar problem with the 'onlastframe' event? I don't seem to have this problem when working with .swf files but again, when mp3s are initially loaded, this event doesn't seem to be called.