Looping Mp3 File And Event.SOUND_COMPLETE
Dear all,
I am trying to find a workaround to the problem of looping mp3 files, basically the silence in the transition (from end to start). I could use wav files but I need to load the file externally, which makes not possible to use wav. So I did this
HTML Code: var channel:SoundChannel = myMp3.play(); channel. addEventListener (Event.SOUND_COMPLETE, onComplete);
function onComplete(event:Event){ channel = assets.sounds.piston.play(); } Then after some time a use this code to stop and remove the listener:
HTML Code: channel.stop(); channel.removeEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
However the problem is still there
Edit: Now I know it is not a problem of flash, it is problem of the mp3 format itself. Any way, is there a workaround?
Thanks in advance
KirupaForum > Flash > ActionScript 3.0
Posted on: 07-03-2007, 04:34 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
SOUND_COMPLETE Event Not Firing
so i've an mp3 in the library that extends the Sound class called MusicHiding instantiated thus:
mh = new MusicHiding();
mh.addEventListener( Event.SOUND_COMPLETE, onPlaybackComplete )
mh.play();
elsewhere:
function onPlaybackComplete ( e:Event ):void
{
trace("onPlaybackComplete ")
}
this method never gets called. what could possibly be preventing that?
AS3: Event.SOUND_COMPLETE Event Not Firing
hey everyone
have a look at the attached code. its not very complex but for some reason i can't get the onPlaybackComplete method to fire. any ideas why? SoundClick is an mp3 in the library set to export as an extension of the Sound class. it plays fine, so presumably extending Sound and accessing its methods is working ok, just cant get that sound_complete event to fire
Attach Code
package ccg.gui {
import ccg.gui.*;
import flash.events.*;
import flash.media.*;
import flash.utils.*;
public class RiderAudio2 {
private var _effectGenericClick:SoundClick;
public function RiderAudio2 ()
{
trace("RiderAudio INIT");
_effectGenericClick = new SoundClick();
_effectGenericClick.addEventListener( Event.SOUND_COMPLETE, onPlaybackComplete );
_effectGenericClick.play();
};
public function onPlaybackComplete ( e:Event ):void
{
trace("RiderAudio onPlaybackComplete ");
};
};
};
Event.SOUND_COMPLETE Firing Early
Hi all... I am creating an mp3 player and have ran into an issue with the seek capability of the application. I want to be able to show the progress of the sound playing and allow the user to click on this progress bar to seek through the sound.
The problem arises when I go to seek past 55 or 60% of the sounds length... the Event.SOUND_COMPLETE fires and the onPlaybackComplete function is called, stopping the sound.
I have just begun experimenting with ActionScript, so any criticism is welcome and much appreciated concerning general code organization and how to fix this problem.
First I extend the DataGrid class to change some of it's behavior, such as column resizing. This class loads the dataProvider for the data grid from a MySQL database. When the user double clicks a row, it launches that mp3 file associated with the data.
In onItemDoubleClick, I create a new MyMP3, passing it my container object that has all the buttons and duration bars, etc on it.
So it seeks fine when I click anywhere on the duration_mc's child, squareHit up until about 55% of the length of the song... though the channel.position traces to be at around 55 or 60% of the sound's length, Event.SOUND_COMPLETE fires a few seconds later. Please advise on how to fix this. Thanks.
Attach Code
// MyMP3DataGrid
package
{
// import statements
import fl.controls.dataGridClasses.DataGridColumn;
...
public class MyMP3DataGrid extends DataGrid
{
private var loadDPCount:int = 0;
private var divider:Sprite;
private var variables:URLVariables;
private var request:URLRequest;
private var loader:URLLoader;
private var dataXML:XML;
private var _dataProviderURL:String;
private var dProvider:DataProvider;
private var _stage:Sprite;
private var lastmp3:MyMP3;
public function MyMP3DataGrid( container:Sprite, dataProviderURL:String )
{
super();
_stage = container;
_dataProviderURL = dataProviderURL;
getDataProvider();
doubleClickEnabled = true;
addEventListener( ListEvent.ITEM_DOUBLE_CLICK, onItemDoubleClick );
}
public function drawDivider():void
{
var dProvider:DataProvider = dataProvider;
divider = new Sprite();
divider.graphics.lineStyle(3, 0xFFcc33, 0.6 );
divider.graphics.moveTo(0,0);
divider.graphics.lineTo(0, (( dProvider.length > 18 ) ? rowHeight * 18 : ( dProvider.length + 1 ) * rowHeight ));
divider.visible = false;
}
override protected function handleHeaderResizeDown(event:MouseEvent):void
{
divider.x = event.stageX;
divider.y = this.y;
_stage.addChild(divider);
divider.visible = true;
super.handleHeaderResizeDown(event);
}
override protected function handleHeaderResizeMove(event:MouseEvent):void
{
divider.x = event.stageX;
}
override protected function handleHeaderResizeUp(event:MouseEvent):void
{
divider.visible = false;
var delta:Number = event.stageX - columnStretchStartX;
var newWidth = columnStretchStartWidth + delta;
resizeColumn(columnStretchIndex, newWidth);
super.handleHeaderResizeUp(event);
}
private function onItemDoubleClick( event:ListEvent ):void
{
if( lastmp3 )
lastmp3.cleanUp();
var mp3info:Object = event.item as Object;
var url:String = './library/'+mp3info.Artist+'/'+mp3info.Album+'/'+mp3info.Name;
var mp3:MyMP3 = new MyMP3( _stage, url, mp3info );
lastmp3 = mp3;
_stage.addChild(mp3);
}
public function getDataProvider():void
{
variables = new URLVariables();
variables.action = "getmp3s";
request = new URLRequest();
request.url = _dataProviderURL;
request.method = URLRequestMethod.POST;
request.data = variables;
loader = new URLLoader();
loader.addEventListener( IOErrorEvent.IO_ERROR, loaderIOErrorHandler );
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
try
{
loader.load(request);
}
catch (error:Error)
{
// TO DO: Output errors to the user in a user friendly way
trace("Unable to load URL");
}
}
private function loaderIOErrorHandler( event:IOErrorEvent ):void
{
loader.removeEventListener( IOErrorEvent.IO_ERROR, loaderIOErrorHandler );
loadDPCount++;
if( loadDPCount < 5 )
getDataProvider();
else
trace('Server offline of busy.');
}
private function loaderCompleteHandler(event:Event):void
{
loader.removeEventListener( Event.COMPLETE, loaderCompleteHandler );
//trace( event.target.data ); // this will display any php errors from mymp3.php
dataXML = XML(event.target.data);
dProvider = new DataProvider(dataXML);
setSize(770, (( dProvider.length > 17 ) ? rowHeight * 18 : ( dProvider.length + 1 ) * rowHeight ));
dataProvider = dProvider;
drawDivider();
if( !visible )
visible = true;
}
}
}
// MyMP3
package
{
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.geom.Rectangle;
import flash.events.*;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.display.Shape;
import flash.display.DisplayObject;
import fl.controls.Button;
import flash.display.MovieClip;
import flash.display.Stage;
import fl.controls.*;
public class MyMP3 extends Sprite
{
private var posTimer:Timer;
//private var position:Number;
private var durationFormat:TextFormat;
private var format:TextFormat;
private var mp3nameTF:TextField;
private var sndFinished:Boolean;
private var s:Sound;
private var trans:SoundTransform;
private var req:URLRequest;
private var channel:SoundChannel;
private var isPlaying:Boolean;
private var pausePosition:Number;
private var squareHit:Sprite;
private var ctimesec:uint;
private var csec:uint;
private var cmin:uint;
private var chour:uint;
private var csecstr:String;
private var cminstr:String;
private var chourstr:String;
private var estimatedLength:int;
private var playbackPercent:uint;
private var square:Shape;
private var isDragging:Boolean;
private static var mp3playing:Boolean = false;
private var _mp3info:Object;
private var playBtn_btn:flatgreyplay; // = new flatgreyplay();
private var pauseBtn_btn:flatgreypause; // = new flatgreypause();
private var durationTF:TextField;
private var playtimeTF:TextField;
private var duration_mc:DurationBG = new DurationBG();
private var _stage:Sprite;
public function MyMP3( container:Sprite, url:String , mp3info:Object )
{
_stage = container;
//trace( _stage );
_mp3info = mp3info;
BuildUI();
Initialize( url );
SetUpEventListeners();
}
public function cleanUp():void
{
posTimer.removeEventListener(TimerEvent.TIMER, UpdateDurationTF );
playBtn_btn.removeEventListener( MouseEvent.CLICK, Play );
pauseBtn_btn.removeEventListener( MouseEvent.CLICK, Pause );
squareHit.removeEventListener( MouseEvent.CLICK, UpdatePosition );
if( isPlaying )
{
posTimer.stop();
pausePosition = 0;
channel.stop();
isPlaying = false;
pauseBtn_btn.visible = false;
playBtn_btn.visible = true;
removeEventListener( Event.ENTER_FRAME, OnEnterFrame );
mp3playing = false;
}
if( square )
removeChild(square);
durationTF.text = '00:00:00';
var tfFormat:TextFormat = new TextFormat();
tfFormat.size = 10;
tfFormat.color = 0xffffff;
tfFormat.font = "Arial";
durationTF.setTextFormat( tfFormat );
}
private function Initialize( url:String )
{
playtimeTF.text = _mp3info.Time;
var tfFormat:TextFormat = new TextFormat();
tfFormat.size = 10;
tfFormat.color = 0xffffff;
tfFormat.font = "Arial";
playtimeTF.setTextFormat( tfFormat );
posTimer = new Timer(50);
sndFinished = false;
trans = new SoundTransform(1, 0);
s = new Sound();
s.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
channel = new SoundChannel();
req = new URLRequest( url );
s.load(req);
isPlaying = false;
pausePosition = 0;
pauseBtn_btn.visible = false;
isDragging = false;
}
private function ioErrorHandler( event:IOErrorEvent ):void
{
trace( event );
}
private function SetUpEventListeners()
{
posTimer.addEventListener(TimerEvent.TIMER, UpdateDurationTF );
playBtn_btn.addEventListener( MouseEvent.CLICK, Play );
pauseBtn_btn.addEventListener( MouseEvent.CLICK, Pause );
//channel.addEventListener(Event.SOUND_COMPLETE, OnPlaybackComplete);
squareHit.addEventListener( MouseEvent.CLICK, UpdatePosition );
var mevent:MouseEvent = new MouseEvent( MouseEvent.CLICK );
playBtn_btn.dispatchEvent( mevent );
}
public function Play(e:MouseEvent)
{
if( !isPlaying && !mp3playing )
{
posTimer.start();
channel = s.play(pausePosition, 0, trans);
if( !channel.hasEventListener(Event.SOUND_COMPLETE))
channel.addEventListener(Event.SOUND_COMPLETE, OnPlaybackComplete);
isPlaying = true;
playBtn_btn.visible = false;
pauseBtn_btn.visible = true;
if( !squareHit.hasEventListener(MouseEvent.CLICK ))
squareHit.addEventListener( MouseEvent.CLICK, UpdatePosition );
addEventListener(Event.ENTER_FRAME, OnEnterFrame);
mp3playing = true;
}
}
private function Pause( e:MouseEvent )
{
if( isPlaying )
{
posTimer.stop();
pausePosition = channel.position;
channel.stop();
isPlaying = false;
pauseBtn_btn.visible = false;
playBtn_btn.visible = true;
removeEventListener( Event.ENTER_FRAME, OnEnterFrame );
mp3playing = false;
}
}
private function OnPlaybackComplete( e:Event )
{
trace( 'onplaybackcomplete' );
posTimer.stop();
isPlaying = false;
pausePosition = 0;
pauseBtn_btn.visible = false;
playBtn_btn.visible = true;
removeChild( square );
square = new Shape();
square.graphics.beginFill(0xFFCC33, 0.5);
square.graphics.drawRect( 0, 0, duration_mc.width, duration_mc.height );
square.graphics.endFill();
square.x = duration_mc.x;
square.y = duration_mc.y;
//square.addEventListener(MouseEvent.CLICK, UpdatePosition);
addChild(square);
removeEventListener( Event.ENTER_FRAME, OnEnterFrame );
channel.removeEventListener(Event.SOUND_COMPLETE, OnPlaybackComplete );
//removeChild(square);
durationTF.text = '00:00:00';
var tfFormat:TextFormat = new TextFormat();
tfFormat.size = 10;
tfFormat.color = 0xffffff;
tfFormat.font = "Arial";
durationTF.setTextFormat( tfFormat );
mp3playing = false;
}
private function UpdatePosition( e:MouseEvent )
{
//trace( squareHit.width, e.localX );
var position:Number = Math.ceil(s.length / (s.bytesLoaded / s.bytesTotal)) * ( e.localX / squareHit.width );
//trace( channel.position, s.length );
//if( position < s.length )
//{
if( isPlaying )
{
channel.stop();
channel = s.play(position, 0, trans);
if( !channel.hasEventListener(Event.SOUND_COMPLETE))
channel.addEventListener(Event.SOUND_COMPLETE, OnPlaybackComplete);
}
else if( !mp3playing )
{
posTimer.start();
channel = s.play(position, 0, trans);
if( !channel.hasEventListener(Event.SOUND_COMPLETE))
channel.addEventListener(Event.SOUND_COMPLETE, OnPlaybackComplete);
isPlaying = true;
playBtn_btn.visible = false;
pauseBtn_btn.visible = true;
if( !squareHit.hasEventListener(MouseEvent.CLICK ))
squareHit.addEventListener( MouseEvent.CLICK, UpdatePosition );
addEventListener(Event.ENTER_FRAME, OnEnterFrame);
mp3playing = true;
}
//}
}
private function OnEnterFrame( e:Event )
{
estimatedLength = Math.ceil(s.length / (s.bytesLoaded / s.bytesTotal));
playbackPercent = Math.round(100 * (channel.position / estimatedLength));
if( square && square.parent == this )
{
//square.removeEventListener( MouseEvent.CLICK, UpdatePosition );
removeChild( square );
}
square = new Shape();
square.graphics.beginFill(0xFFCC33, 0.5);
square.graphics.drawRect( duration_mc.x, duration_mc.y, ( playbackPercent / 100 ) * ( squareHit.width), squareHit.height );
square.graphics.endFill();
//square.addEventListener( MouseEvent.CLICK, UpdatePosition );
addChild(square);
}
private function BuildUI()
{
// play button
playBtn_btn = _stage.getChildByName('playBtn_btn') as flatgreyplay;
// pause button
pauseBtn_btn = _stage.getChildByName('pauseBtn_btn') as flatgreypause;
// volume bar
/*volumeBarBtn = CreateVolumeBar();
volumeBarBtn.x = playBtn.width + 3;
volumeBarBtn.y = 0;
this.addChild(volumeBarBtn);*/
// duration textfield
durationTF = _stage.getChildByName('durationTF') as TextField;
// duration_mc
duration_mc = _stage.getChildByName('duration_mc') as Slider;
// playtime textfield
playtimeTF = _stage.getChildByName('playtimeTF') as TextField;
// mp3 name textfield
mp3nameTF = _stage.getChildByName('mp3nameTF') as TextField;
mp3nameTF.text = _mp3info.Name;
var nFormat:TextFormat = new TextFormat();
nFormat.font = "Arial";
nFormat.color = 0xffffff;
nFormat.size = 12;
nFormat.bold = true;
mp3nameTF.setTextFormat(nFormat);
// mp3 position hit area
squareHit = new Sprite();
squareHit.graphics.beginFill(0x000000, 0);
squareHit.graphics.drawRect( 0, 0, duration_mc.width, duration_mc.height);
squareHit.graphics.endFill();
squareHit.buttonMode = true;
squareHit.x = duration_mc.x;
squareHit.y = duration_mc.y;
addChild(squareHit);
}
private function UpdateDurationTF(e:TimerEvent)
{
ctimesec = Math.floor( channel.position / 1000 );
chour = Math.floor( ctimesec / 60 / 60 );
if( chour < 10 ) chourstr = '0' + chour;
else chourstr = chour.toString(10);
cmin = Math.floor(ctimesec / 60);
if( cmin < 10 ) cminstr = '0' + cmin;
else cminstr = cmin.toString(10);
csec = Math.floor( ctimesec % 60);
if( csec < 10 ) csecstr = '0' + csec;
else csecstr = csec.toString(10);
durationTF.text = chourstr + ':' + cminstr + ':' + csecstr;
var tfFormat:TextFormat = new TextFormat();
tfFormat.size = 10;
tfFormat.color = 0xffffff;
tfFormat.font = "Arial";
durationTF.setTextFormat( tfFormat );
}
}
}
On Sound_Complete
Hi Forum folk,
I have a question about looping audio in flash.
If for example I want to play a looped sound in flash I can put in the following code and the sound loops seamlessly
this.sndChannel=sound.play(0,2);
I however wanted to loop sound using the Sound_Complete Event to have a bit more control.
public function playAudio(){
this.sndChannel=sound.play();
this.sndChannel.addEventListener(Event.SOUND_COMPLETE,loopMusic);
}
public function loopMusic(e:Event) {
if(this.sndChannel!=null){
this.sndChannel.removeEventListener(Event.SOUND_COMPLETE,loopMusic);
playAudio();
}
}
The sound loops but there is a gap between the song ending and beginning again.
I wanted to know to know how does the internal looping of audio (first example) work in flash. How does flash know when the end of the audio has arrived and to play it again? What mechanism does the looping use (which works well) and can I get in at it.
Thanks,
dub
Help With SOUND_COMPLETE
I've tried several different paths to reset the count to position "o" using Sound_Complete, but apparent;y I
i'm grasping the concept.
Here's what I have for the player... it's just one sound, which I want to replay on another "click" without playing ove ritself.
Help would be greatly appreaciated.
var song:Sound = new Sound;
var sndChan:SoundChannel = new SoundChannel;
var songPlaying:Boolean = false;
var pos:Number;
import flash.utils.getDefinitionByName;
import flash.media.Sound;
var librarySound:Class = getDefinitionByName ( "human_resources.mp3" ) as Class;
song = new librarySound();
play_btn.addEventListener(MouseEvent.CLICK, playSong);
stop_btn.addEventListener(MouseEvent.CLICK, stopSong);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSong);
function playSong(event:Event):void
{
if(songPlaying == false)
{
songPlaying = true;
sndChan = song.play(pos);
play_btn.removeEventListener(MouseEvent.CLICK, playSong);
}
}
function stopSong(event:Event):void
{
sndChan.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK, playSong);
pos = 0;
}
function pauseSong(event:Event):void
{
pos = sndChan.position;
sndChan.stop();
songPlaying = false;
play_btn.addEventListener(MouseEvent.CLICK, playSong);
}
SOUND_COMPLETE Help Please , Not Sure Sure How It Works
Hi guys i wonder if anyone can help me. ive got a button that when you press it it an audio file plays, a button to pause it and a button to stop it. i think ive got all the code for this working. my problem is that when the audio comes to the end id like the play button to be made visible and the audio to play from the begining again when you press play.
heres my code
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.*;
var soundReq:URLRequest = new URLRequest("free_fade.mp3");
var sound:Sound = new Sound();
var soundChannel:SoundChannel = new SoundChannel();
var soundPosition:Number = 0;
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void {
play_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
}
//***
function playSound(event:MouseEvent):void {
soundChannel = sound.play(soundPosition);
pause_btn.visible = true;
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
play_btn.visible =false;
play_btn.removeEventListener(MouseEvent.CLICK, playSound);
}
function pauseSound(event:MouseEvent):void {
soundPosition = soundChannel.position;
soundChannel.stop();
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible =false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
}
function stopSound(event:MouseEvent):void {
soundChannel.stop();
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible =false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
soundPosition = 0;
}
pause_btn.visible = false;
//****
soundChannel.addEventListener(Event.SOUND_COMPLETE , soundComplete);
function soundComplete(pevent:Event):void {
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible =false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
soundPosition = 0;
}
Looping Clip Event Code Help?
having trouble with a clip being able to loop.
example: i have a movieclip named box.
the code on that movieclip is:
onClipEvent (enterFrame) {
this._x+=30;
}
it moves across the screen fine and all, but when its x coordinate reached 400, i want it to go back to x=5. i tried an "if" statement but it didn't work.
any ideas?
thanks
Button Event Looping Problem
Hi All,
I have created five button. onPress function not working in for loop.
Attach Code
var kk = new Array(mc1, mc2, mc3, mc4, mc5);// these are buttons
var alltext = new Array("keshao", "arun", "parag", "chintu", "manish");// these are strings
var i:Number;
for (i=0; i<alltext.length; i++) {
kk[i].onPress = function() {
ss.text = alltext[i];
};
}
SOUND_COMPLETE With Imported Sound
I would like to be able to import these short audio voiceovers and wait on a frame until they complete playing before moving on. The script below works with external sounds , but I don't know how to declare the var if the sound is just loaded into a frame. Thanks.
stop()
var soundReq:URLRequest = new URLRequest("Audio2.mp3");
var sound:Sound = new Sound();
sound.load(soundReq);
var soundControl:SoundChannel = sound.play();
soundControl.addEventListener(Event.SOUND_COMPLETE , onEnd);
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
sound.play();
}
function onEnd (event:Event):void
{
trace("done!!!");
gotoAndPlay(2);
}
XML Mp3 Player - SOUND_COMPLETE Problem
Hi all. It's been a long time since the last time I posted here.
I'm building a XML mp3 player in AS 3, and I'm trying to make it have the common capabilities from the usual players, such as windows media player and so on.
So I have rewind/forward btns, shuffle (not working very well yet, but I think I can solve it on my own), repeat, volume control, and my problem (it seems to be the problem), a search position bar, I mean, I've a kind of load bar that shows the position of the current track, and when you press a little bar (movie clip) and move it across the bar behind it loads the sound from the place you release it (like wmp, once again ).
And as there are 60+ songs loaded by the XML I've a SOUND_COMPLETE function to jump to the next track if no repeat or shuffle are selected. It works great if I don't change the position of the song, when it reaches the end it jumps to next track. If I changed the position previously, it doesn't.
From what I got (with tracing position/duration and the image attached) when I do this the music does not reach the end by some miliseconds, but it changes everything once the function only runs when it finishes completely.
I'm attaching my xml code, the action script and an image with the instances and there you can see that the music doesn't reaches the end.
My XML file is like this:
Code:
<?xml version='1.0' encoding='UTF-8'?>
<musicas>
<faixa>
<artista>Breaking Benjamin</artista>
<musica>01-linkin_park-foreword-h8me.mp3</musica>
<nomeMusica>The Diary Of Jane (Acoustic)</nomeMusica>
<imagemCd>Phobia.jpg</imagemCd>
<nomeCd>Phobia</nomeCd>
<duracao>03:18</duracao>
</faixa>
<faixa>
<artista>30 Seconds To Mars</artista>
<musica>30 Seconds To Mars - A Beautiful Lie - From Yesterday (Acoustic).mp3</musica>
<nomeMusica>From Yesterday (Acoustic)</nomeMusica>
<imagemCd>A Beautiful Lie.jpg</imagemCd>
<nomeCd>A Beautiful Lie</nomeCd>
<duracao>04:08</duracao>
</faixa>
<musicas>
My action script (I know it is very confuse, and probably I've some things on it that I could do in a better way, if someone has suggestions I'll be gratefull):
Code:
var total:Number = undefined;
var dadosXML:XML = new XML();
var xDoc:XMLDocument = new XMLDocument();
var som:Sound = new Sound();
var somChannel:SoundChannel = new SoundChannel();
var somTransform:SoundTransform = new SoundTransform();
var muteToFalseTransform:SoundTransform = new SoundTransform();
var muteToTrueTransform:SoundTransform = new SoundTransform();
var played:Boolean = false;
var somPaused:Boolean;
var somStop:Boolean;
var muted:Boolean = false;
var repeat:Boolean;
var shuffle:Boolean;
var newPosition:Number = 0;
var posicao:Number = 0;
var imgLoader:Loader = new Loader();
var musicaActual:Number = 0;
var volRect:Rectangle = new Rectangle(fundoVolume.x,fundoVolume.y,fundoVolume.width,0);
var loadRect:Rectangle = new Rectangle(preloadBar.x,preloadBar.y,preloadBar.width,0);
volumeBall.x = volumeBar.x + volumeBar.width;
soundPosition.x = loadBar.x;
var XMLLoader:URLLoader = new URLLoader();
XMLLoader.addEventListener(Event.COMPLETE, montar);
XMLLoader.load(new URLRequest("musicas.xml"));
function montar(event:Event){
dadosXML = new XML(event.target.data);
xDoc.parseXML(dadosXML);
total = dadosXML.faixa.length();
carregarMusica(0);
}
soundPosition.addEventListener(Event.ENTER_FRAME, iniciar);
soundPosition.addEventListener(MouseEvent.MOUSE_DOWN, dragPosition);
function iniciar(event:Event):void {
soundPosition.x = loadBar.x + ((somChannel.position/som.length)*preloadBar.width);
loadBar.width = soundPosition.x - loadBar.x;
}
function dragPosition(event:MouseEvent):void {
soundPosition.removeEventListener(Event.ENTER_FRAME, iniciar);
loadBar.addEventListener(Event.ENTER_FRAME, searchPosition);
stage.addEventListener(MouseEvent.MOUSE_UP, soundPositionUp);
soundPosition.startDrag(true, loadRect);
}
function searchPosition(event:Event):void {
loadBar.width = soundPosition.x - preloadBar.x;
}
function soundPositionUp(event:MouseEvent):void {
soundPosition.stopDrag();
loadBar.addEventListener(Event.ENTER_FRAME, searchPosition);
stage.removeEventListener(MouseEvent.MOUSE_UP, soundPositionUp);
somChannel.stop();
newPosition = Math.round(((soundPosition.x-preloadBar.x)/preloadBar.width) * som.length);
somChannel = som.play(newPosition);
soundPosition.addEventListener(Event.ENTER_FRAME, iniciar);
}
function carregarMusica(actual:Number):void {
som = new Sound();
som.addEventListener(Event.COMPLETE, soundLoaded);
som.load(new URLRequest(dadosXML.faixa.musica[actual]));
faixa.text = dadosXML.faixa.nomeMusica[actual];
artista.text = dadosXML.faixa.artista[actual];
cd.text = dadosXML.faixa.nomeCd[actual];
duracao.text = dadosXML.faixa.duracao[actual];
imgLoader.load(new URLRequest(dadosXML.faixa.imagemCd[actual]));
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, drawImage);
somChannel.soundTransform = somTransform;
somChannel = som.play();
if(muted == true) {
var muteToTrueTransform = new SoundTransform(0,0);
somChannel.soundTransform = muteToTrueTransform;
}
playPause.gotoAndStop(10);
somChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
somPaused = false;
somStop = false;
musicaActual = actual;
playPause.removeEventListener(MouseEvent.CLICK, playPausePress);
stopBtn.removeEventListener(MouseEvent.CLICK, stopBtnPress);
previousBtn.removeEventListener(MouseEvent.CLICK, previousBtnPress);
nextBtn.removeEventListener(MouseEvent.CLICK, nextBtnPress);
repeatBtn.removeEventListener(MouseEvent.CLICK, repeatBtnPress);
shuffleBtn.removeEventListener(MouseEvent.CLICK, shuffleBtnPress);
volumeBall.removeEventListener(MouseEvent.MOUSE_DOWN, volumeBallDown);
volumeBall.removeEventListener(MouseEvent.MOUSE_UP, volumeBallUp);
muteBtn.removeEventListener(MouseEvent.CLICK, muteBtnPress);
}
function soundComplete(event:Event):void {
switch(repeat) {
case true:
if(played == false){
somChannel.stop();
somChannel = som.play(0);
played = true;
}else{
if(musicaActual < (total-1)) {
musicaActual++;
carregarMusica(musicaActual);
}else{
musicaActual = 0;
carregarMusica(musicaActual);
}
played = false;
}
break;
}
switch(shuffle){
case true:
var num1:Number = Math.round(Math.random() * total-1);
carregarMusica(num1);
break;
}
switch((shuffle) && (repeat)){
case true:
if(played == false){
somChannel.stop();
somChannel = som.play(0);
played = true;
break;
}else{
var num2:Number = Math.round(Math.random() * total-1);
carregarMusica(num2);
played = false;
break;
}
}
if((repeat == false) && (shuffle==false)) {
if(musicaActual < (total-1)) {
musicaActual++;
carregarMusica(musicaActual);
}else{
musicaActual = 0;
carregarMusica(musicaActual);
}
}
}
function drawImage(event:Event):void {
var mc:Sprite = new Sprite();
var bitmap:BitmapData = new BitmapData(imgLoader.width,imgLoader.height,false);
bitmap.draw(imgLoader, new Matrix());
var matrix:Matrix = new Matrix();
mc.graphics.beginBitmapFill(bitmap,matrix,true);
mc.graphics.drawRect(0,0,104,104);
mc.graphics.endFill();
mc.width = mc.height = 166;
mc.x = 120;
mc.y = 117;
this.addChild(mc);
}
function soundLoaded(event:Event){
playPause.addEventListener(MouseEvent.CLICK, playPausePress);
stopBtn.addEventListener(MouseEvent.CLICK, stopBtnPress);
previousBtn.addEventListener(MouseEvent.CLICK, previousBtnPress);
nextBtn.addEventListener(MouseEvent.CLICK, nextBtnPress);
repeatBtn.addEventListener(MouseEvent.CLICK, repeatBtnPress);
shuffleBtn.addEventListener(MouseEvent.CLICK, shuffleBtnPress);
volumeBall.addEventListener(MouseEvent.MOUSE_DOWN, volumeBallDown);
muteBtn.addEventListener(MouseEvent.CLICK, muteBtnPress);
}
function playPausePress(event:MouseEvent):void {
if(somPaused == false) {
playPause.gotoAndStop(1);
posicao = somChannel.position;
somChannel.stop();
somPaused = true;
}else{
playPause.gotoAndStop(10);
somChannel = som.play(posicao);
somPaused = false;
somStop = false;
}
if(somStop == true) {
soundPosition.addEventListener(Event.ENTER_FRAME, iniciar);
playPause.gotoAndStop(10);
somChannel = som.play(0);
somStop = false;
somPaused = false;
}
if(muted == true){
var muteToTrueTransform = new SoundTransform(0,0);
somChannel.soundTransform = muteToTrueTransform;
}
}
function stopBtnPress(event:MouseEvent):void {
somChannel.stop();
soundPosition.removeEventListener(Event.ENTER_FRAME, iniciar);
soundPosition.x = loadBar.x;
loadBar.width = 0;
playPause.gotoAndStop(1);
posicao = 0;
somStop = true;
}
function previousBtnPress(event:MouseEvent):void {
somChannel.stop();
if((somPaused == true) || (somStop == true)) {
if(musicaActual > 0) {
musicaActual--;
carregarMusica(musicaActual);
playPause.gotoAndStop(1);
somChannel.stop();
somStop = true;
}else{
musicaActual = total-1;
carregarMusica(musicaActual);
somChannel.stop();
playPause.gotoAndStop(1);
somStop = true;
}
}else{
playPause.gotoAndStop(10);
if(musicaActual > 0) {
musicaActual--;
carregarMusica(musicaActual);
}else{
musicaActual = total-1;
carregarMusica(musicaActual);
}
}
}
function nextBtnPress(event:MouseEvent):void {
somChannel.stop();
if((somPaused == true) || (somStop == true)) {
if(musicaActual < (total-1)) {
musicaActual++;
carregarMusica(musicaActual);
somChannel.stop();
playPause.gotoAndStop(1);
somStop = true;
}else{
musicaActual = 0;
carregarMusica(musicaActual);
somChannel.stop();
playPause.gotoAndStop(1);
somStop = true;
}
}else{
playPause.gotoAndStop(10);
if(musicaActual < (total-1)) {
musicaActual++;
carregarMusica(musicaActual);
}else{
musicaActual = 0;
carregarMusica(musicaActual);
}
}
}
function repeatBtnPress(event:MouseEvent):void {
if(repeat == false) {
repeat = true;
}else{
repeat = false;
}
}
function shuffleBtnPress(event:MouseEvent):void {
if(shuffle == false){
shuffle = true;
}else{
shuffle = false;
}
}
function volumeBallDown(event:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_UP, volumeBallUp);
volumeBall.startDrag(true, volRect);
volumeBall.addEventListener(Event.ENTER_FRAME, setVolume);
}
function setVolume(event:Event):void {
volumeBar.width = volumeBall.x-fundoVolume.x;
if(muted == false) {
trace((volumeBall.x-fundoVolume.x)/fundoVolume.width);
var somTransform = new SoundTransform((volumeBall.x-fundoVolume.x)/fundoVolume.width, 0);
somChannel.soundTransform = somTransform;
}
}
function volumeBallUp(event:MouseEvent):void {
volumeBall.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, volumeBallUp);
}
function muteBtnPress(event:MouseEvent):void {
if(muted == true) {
var muteToFalseTransform = new SoundTransform((volumeBall.x-fundoVolume.x)/fundoVolume.width, 0);
somChannel.soundTransform = muteToFalseTransform;
muted = false;
muteBtn.gotoAndStop(1);
}else{
var muteToTrueTransform = new SoundTransform(0,0);
somChannel.soundTransform = muteToTrueTransform;
muted = true;
muteBtn.gotoAndStop(10);
}
}
And the image with the essential things (I hope you understand it):
If someone knows what is wrong please help.
Thanks in advance.
Keydown Event And Looping Movieclip Animation
Hi there,
I've been annoying myself to tears with this animation. I am using Flash CS3 and also using AS3 to program a movieclip.
I have made a simple animation of a stickman. It is animated inside a movieclip. He would walk left or right depending what buttons you pressed. I am able to move the the stickman across the screen.
What I want to achieve is when the user press the left or right arrow, it would 'gotoAndPlay' a particular frame and loop from there until the user releases the key. The loop animation is the stickman lifting his leg and pointing forward as if he is to going step forward.
So the pseudo code is:
On keydown
Move stickman across screen
Loop through frame 5 to 10
on keyup
Stop stickman from moving across screen
Stop looping through animation. Make him stand still
The code below is placed in frame 1 of the main Flash movie. The stickman on the stage has an instance name 'bluestick_mc'.
Code:
function moveHero(myevent:KeyboardEvent):void {
// WALK TO RIGHT
if (myevent.keyCode == Keyboard.RIGHT && myevent.shiftKey == false) {
bluestick_mc.x += 1;
bluestick_mc.gotoAndPlay(5);
//bluestick_mc.gotoAndStop(5);
//bluestick_mc.gotoAndStop(8);
}
// RUN TO RIGHT
if (myevent.keyCode == Keyboard.RIGHT && myevent.shiftKey == true) {
bluestick_mc.x += 5;
bluestick_mc.gotoAndPlay(5);
//bluestick_mc.gotoAndStop(5);
//bluestick_mc.gotoAndStop(8);
}
// WALK TO LEFT
if (myevent.keyCode == Keyboard.LEFT && myevent.shiftKey == false) {
bluestick_mc.x -= 1;
bluestick_mc.gotoAndPlay(5);
//bluestick_mc.gotoAndStop(5);
//bluestick_mc.gotoAndStop(8);
}
// RUN TO LEFT
if (myevent.keyCode == Keyboard.LEFT && myevent.shiftKey == true) {
bluestick_mc.x -= 5;
bluestick_mc.gotoAndPlay(5);
//bluestick_mc.gotoAndStop(5);
//bluestick_mc.gotoAndStop(8);
}
}
function stopHero(myevent:KeyboardEvent):void {
bluestick_mc.gotoAndStop(1);
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveHero);
stage.addEventListener(KeyboardEvent.KEY_UP, stopHero);
Inside the movieclip 'bluestick_mc', at frame 1, I've placed a 'stop();' actionscript. That's it, nothing else.
The problem is when I press the left or right key, the 'goAndPlay(5)' inside the 'moveHero' function would execute once. Yes, it would lift its leg and step forward but after the first loop, it continued to walk across the screen with the leg up in the air. My guess is that when I continued to hold down the left/right arrow, it plays frame 5 and does not advance.
I tried this approach.
Code:
// WALK TO RIGHT
if (myevent.keyCode == Keyboard.RIGHT && myevent.shiftKey == false) {
bluestick_mc.x += 1;
//bluestick_mc.gotoAndPlay(5);
bluestick_mc.gotoAndStop(5);
bluestick_mc.gotoAndStop(8);
}
It would skip straight to frame 8. You don't see frame 5 at all. I didn't understand this was happening so that's why those two lines were commented out.
The Flash movie plays at 35 frames a second, so I thought that might be a problem, so I lowered it hoping I would see it animated but I was wrong.
I would like to hold down the left or right arrow and see the walking animation being looped from frame 5 to 10. So what exactly am I doing wrong? I tried to find a solution here but I didn't turn up anything.
I attach the FLA file for your examination.
Can anyone please give any suggestions?
SoundChannel SOUND_COMPLETE Sequential Sounds
Trying to work up a simple file that'll play audio files from the library sequentially. Seemd straightforward enough but only the first SOUND_COMPLETE is working so I'm missing something here.
Code:
import flash.media.Sound;
import flash.media.SoundChannel;
var mySoundOne:Sound = new SoundOne();
var mySoundTwo:Sound = new SoundTwo();
var mySoundThree:Sound = new SoundThree();
var mySoundChannel:SoundChannel = new SoundChannel();
mySoundChannel = mySoundOne.play();
mySoundChannel.addEventListener(Event.SOUND_COMPLETE, sound_1_Complete);
var mySoundChannel2:SoundChannel = new SoundChannel();
mySoundChannel2.addEventListener(Event.SOUND_COMPLETE, sound_2_Complete);
var mySoundChannel3:SoundChannel = new SoundChannel();
mySoundChannel3.addEventListener(Event.SOUND_COMPLETE, sound_3_Complete);
function sound_1_Complete(event:Event):void {
trace("one complete");
mySoundChannel2 = mySoundTwo.play();
}
function sound_2_Complete(event:Event):void {
trace("two complete");
mySoundChannel3 = mySoundThree.play();
}
function sound_3_Complete(event:Event):void {
trace("three complete");
}
Looping Action Script Till Event Is Complete
Hi
Whilst an external movie clip is playing back, i want to disable
a) the button that called it
b) the remaining six buttons that form my navigation
Until playback of the movie clip is complete, then I want to 'activate' all the buttons again.
Here is the website I am trying to make work
http://www.gdbr09729.pwp.blueyonder.co.uk/severnac.html
You can see that I want to disable the buttons because, clicking on any of the menus whilst another external movie is playing causes that movie clip to overlay the one that is still playing itself. my code (im a noobie to actionscript) will work fine if I can disable those buttons!
Im looking at using a 'while' loop but dont seem able to make it work. Any help would be dearly appreciated
Graham
[Edited by FlashManAndRobin on 11-14-2001 at 07:15 PM]
Looping A .flv File?
Hi All.
I am using the Flash 8 video player component that has a component panel which I can input one .flv path url. How can it tell it to LOOP a second .flv after the first one is done?
Please advise.
Thank you!
My .swf File Keeps Looping
The .swf file that I published won't stop on the last frame. I've already made sure that Loop is not checked in in the playback section of the publish settings. Coud it have something to do with how the file is embedded into the web page? The code from the web page that I'm trying to play the video on is attached at the end.
Now, on the last frame of the .fla file there is a button and I added some actionscript to that frame so that it will advance to the next page. Here is what the actionscript looks like...
import flash.events.MouseEvent;
/*This script will send a page submit command to the survey.*/
function gotoNextPage(event:MouseEvent) :void
{
var nextSurveyPage:URLRequest = new URLRequest("javascript:submitpage(1)");
navigateToURL(nextSurveyPage);
}
nextPage_btn.addEventListener(MouseEvent.CLICK,gotoNextPage);
Any suggestions as to what the problem might be and what the solution is would be very helpful.
Thanks
Attach Code
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="600" height="417" id="myMovieName">
<param name="movie" value="http://static.targetrx.com/mm/slideshows/swf_controller.swf?csConfigFile=http://static.targetrx.com/mm/slideshows/sean/sean_config.xml"/>
<param name="quality" value="high"/>
<param name="menu" value="false"/>
<param name="bgcolor" value="#FFFFFF"/>
<param name="FlashVars" value="csConfigFile=gttp://static.targetrx.com/mm/slideshows/sean/sean_config.xml"/>
<embed src="http:..static.targetrx.com/mm/slideshows/swf_controller.swf?csConfigFile=http://static.targetrx.com/mm/slideshows/sean/sean_config.xml" FlashVars="csConfigFile=http://static.targetrx.com/mm/slideshows/sean/sean_config.xml" quality="high" bgcolor="#FFFFFF" width="600" height="417" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>
File Keeps Looping
I created a document in fireworks and imported it into Flash. I decided to add the timeline effect, transition. The .jpg now loads a section of a time from the top until the whole file is displayed. this I can live with, but the loopin' of it. I've made sure all options pertainin' to looping are turned off but it still restarts once picture is finally loaded. I'll appreciate any help to end my frustration.
Thankz
Looping FLV File
Hello,
I simply want to loop an external FLV file.
Using flash 8, with the standard Import Video wizard.
I have put my FLV file on my server already.
I have seen a couple of topics about it and some mentioned about NetStream... well... the codes seamed complete and working, however, what, when, where how do I add it to my project!
thanks
File Keeps Looping
I created a document in fireworks and imported it into Flash. I decided to add the timeline effect, transition. The .jpg now loads a section of a time from the top until the whole file is displayed. this I can live with, but the loopin' of it. I've made sure all options pertainin' to looping are turned off but it still restarts once picture is finally loaded. I'll appreciate any help to end my frustration.
Thankz
Continuously Looping Swf File
I'm sure this is a retarded question - but......
I have imported a SWF file into my fla. However, when I try to publish the fla. file as a SWF, the original SWF is on a continuous loop. This despite me going into the original SWF and changing publishing settings, the instance behaviour to play once and anything else I can think of.
I have also tried changing these things in my fla. file before publishing, but I can't stop it looping.
If anyone could help I'd be extremely grateful.
Dan.
Stoping A Swf File From Looping
I only have access to this Swf file not the Fla. the current swf file loops over and over I was wondering is there a way to stop this. It will need to sit on a html web page.
Cheers.
This File Won't Stop Looping
I have built a simple interactive movie to view my portfolio. It uses two arrows, one that goes forward to the next image and one that goes backwards to the previous images. The problem occurs when you click continuously too fast on an arrow. The image that loads loops repeatedly. Then every image that loads after that loops repeatedly as well. I have put the code below.
To view the page use the link below and click on portfolio link http://www.cthrugraphix.com/htm_homepage.htm
//passes a value of 1 to the function to load the first image
counter=1;
photochange(counter);
//next button that either sets the value to 16 or adds a value
// to the variable counter
next_btn.onPress=function() {
if (counter>=16) {
counter=16;
photochange(counter);
} else {
photochange(counter+=1);
}
}
//back button that either sets the value to 1 or subtracts a value
// from the variable counter
back_btn.onPress=function() {
if (counter<=1) {
counter=1;
photochange(counter);
} else {
photochange(counter-=1);
}
}
//function that passes counter to load images
function photochange(counter) {
slideshow_mc.loadMovie("photo"+counter+".swf");
loadVariablesNum("des"+counter+".txt",0);
loadVariablesNum("bod"+counter+".txt",0);
loadVariablesNum("email.txt",0);
}
Looping Through External File
hello!
i have an external xml file which i am trying to get flash to loop through and extract the data from, i've written one loop for it which i learnt from actionscript.org but this won't work.
the xml file i'm trying to loop through is here:
http://www.suckmyrazor.org/blog/flash.xml
and as you can see it has a parent node <blog> and then children nodes of <item> (each with there own children) and this is as deep as it'll go (for the moment)
the loop i have is this:
Code:
function processBlog(xmlDoc_xml) {
for (var n = 0; n<xmlDoc_xml.firstChild.firstChild.childNodes.length; n++) {
trace(xmlDoc_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue);
}
}
what i really need is a loop that loops through each <item> node and then loops through each child node of the <item> node, it tried doin this :
Code:
function processBlog(xmlDoc_xml) {
for (var n = 0; n<xmlDoc_xml.firstChild.firstChild.childNodes.length; n++) {
for (var j = 0; j<xmlDoc_xml.firstChild.firstChild.childNodes.length; j++) {
trace(xmlDoc_xml.firstChild.firstChild.childNodes[j].firstChild.nodeValue);
}
}
}
but this crashed flash! oh btw, i'm using mx 2004 pro publishing in as2 flash 7...
please help!
Looping A Sound File
Hi i want to add a sound loop to my site to allow a soft bit of music to play in my background, can i ask how i make the loop continously play if i have placed my sound file in a single keyframe?
thanks
Looping Through A Text File
I've been trying to find tutorials on this all morning. I have a text file that looks like this:
Code:
&myVar1 = Text1&myVar2 = Text2&myVar3 = Text3
I have a flash file:
Code:
var my_lv = new LoadVars();
my_lv.onLoad = function(ok)
{
if (ok)
{
my_mc.i_text.text = this.myVar
}
Else
{
trace("an error has occured");
}
};
my_lv.load("textfile.txt");
My idea was to take a variable like "x" and have it increase by 1 each time the movie loops. Then I would add myVar+x to get myVar2, myVar3 and so on. I know how to do this in ASP... lol, it's not the same in Flash. Any suggestions or pointing me in the right direction would help!
Thanks
MP3 Looping & Pulling URL From .txt File
Hello! I'm working on a file and I've run into two problems. The first is I cannot get the sound/mp3 file to loop. The second problem is I'd like the "Order Photos" to be a button and for the URL to be pulled from the .txt file.
You can view what I have at:
http://www.visbuilder.com/flash/wedding/wedding2.html
You can download a .zip file of the flash file, mp3, .txt file, etc. at:
http://www.visbuilder.com/flash/wedding/wedding.zip
I'm using Flash MX 2004.
Thanks in advance for your help!
Michelle
Looping Audio File Using AS
Hi,
I have this code to load in an audio file from a different source on the internet.
Code:
// Create a new Sound object to play the sound.
var songTrack:Sound = new Sound();
// Create the polling function that tracks download progress.
// This is the function that is "polled." It checks
// the downloading progress of the Sound object passed as a reference.
function checkProgress (soundObj:Object):Void {
var numBytesLoaded:Number = soundObj.getBytesLoaded();
var numBytesTotal:Number = soundObj.getBytesTotal();
var numPercentLoaded:Number = Math.floor(numBytesLoaded / numBytesTotal * 100);
if (!isNaN(numPercentLoaded)) {
trace(numPercentLoaded + "% loaded.");
}
};
// When the file has finished loading, clear the interval polling.
songTrack.onLoad = function ():Void {
trace("load complete");
clearInterval(poll);
};
// Load streaming MP3 file and start calling checkProgress(),
songTrack.loadSound("sounds/intro.mp3", true);
var poll:Number = setInterval(checkProgress, 100, songTrack);
How do I get it to loop? What bit of code would I need to add to this?
Thanks
Looping Audio File Using AS
Hey,
I have this code:
Code:
// Create a new Sound object to play the sound.
var songTrack:Sound = new Sound();
// Create the polling function that tracks download progress.
// This is the function that is "polled." It checks
// the downloading progress of the Sound object passed as a reference.
function checkProgress (soundObj:Object):Void {
var numBytesLoaded:Number = soundObj.getBytesLoaded();
var numBytesTotal:Number = soundObj.getBytesTotal();
var numPercentLoaded:Number = Math.floor(numBytesLoaded / numBytesTotal * 100);
if (!isNaN(numPercentLoaded)) {
trace(numPercentLoaded + "% loaded.");
}
};
// When the file has finished loading, clear the interval polling.
songTrack.onLoad = function ():Void {
trace("load complete");
clearInterval(poll);
};
// Load streaming MP3 file and start calling checkProgress(),
songTrack.loadSound("sounds/intro.mp3", true);
var poll:Number = setInterval(checkProgress, 100, songTrack);
I want to be able to loop the imported Audio sound, does anybody know how to do this?
Thanks
Looping External Mp3 File
hello all!
need some help on figuring out how to make my external streaming mp3 file loop. I tried a few things but i'm having no luck. here is my code where everything works fine now minus the code for looping.
thanks for looking.
houston
playList = ["url"];
currentSong = 0;
maxSongs = playList.length -1;
function startStreaming(){
mp3 = new Sound();
mp3.loadSound(playList[currentSong], true);
mp3.onSoundComplete = function(){
currentSong ++;
if (currentSong > maxSongs){
currentSong = 0;}
delete mp3;
}
}
startStreaming();
stop();
stop();
Looping Through File-directory XML
I was wondering if this is possible using e4x/nodes (possibly in combination?)
I have an xml file that has a file/directory structure - it's got nested directories (naturally) so i'm not sure how to read through the XML file..or if it's even possible given how XML works...
Here is my output:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<structure>
<DIR>
<file>/Users/Chris/Sites/_resources/_images/image1.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image2.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image3.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image4.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image5.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image6.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image7.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image8.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/image9.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/left.psd</file>
<file>/Users/Chris/Sites/_resources/_images/middle.psd</file>
<file>/Users/Chris/Sites/_resources/_images/right.psd</file>
<file>/Users/Chris/Sites/_resources/_images/thumb1.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb2.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb3.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb4.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb5.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb6.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb7.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb8.jpg</file>
<file>/Users/Chris/Sites/_resources/_images/thumb9.jpg</file>
</DIR>
<DIR>
<DIR>
<file>/Users/Chris/Sites/_resources/_packages/_gallery/AC_RunActiveContent.js</file>
<file>/Users/Chris/Sites/_resources/_packages/_gallery/gallery.as</file>
<file>/Users/Chris/Sites/_resources/_packages/_gallery/image.as</file>
<file>/Users/Chris/Sites/_resources/_packages/_gallery/thumbnail.as</file>
</DIR>
<DIR>
<file>/Users/Chris/Sites/_resources/_packages/_gallery2/gallery.as</file>
<file>/Users/Chris/Sites/_resources/_packages/_gallery2/image.as</file>
<file>/Users/Chris/Sites/_resources/_packages/_gallery2/thumbnail.as</file>
</DIR>
<DIR>
<file>/Users/Chris/Sites/_resources/_packages/_preloader/preloader.as</file>
</DIR>
</DIR>
<DIR>
<file>/Users/Chris/Sites/_resources/_xml/gallery.xml</file>
</DIR>
<file>/Users/Chris/Sites/_resources/AlphaMasking.zip</file>
<file>/Users/Chris/Sites/_resources/ape_a045.zip</file>
<file>/Users/Chris/Sites/_resources/BloodEffect.as</file>
<file>/Users/Chris/Sites/_resources/dropMenu.ZIP</file>
<file>/Users/Chris/Sites/_resources/Example.zip</file>
</structure>
As you can see, there is some nested DIR's - can anyone point me in the right direction to loop through this - my main goal would be to add it all into a multi-dim array where each directory is a new array and it's items are files. Other suggestions are welcome, of course.
Am I going about this totally wrong?
Can anyone point me in the right direction for reading through this xml file?
Looping External Swf File
I am working on a project that includes a basic scene with a few layers. On one layer I have the company logo, and on the other layer I have an action in the first keyframe to load an external swf file.
This external swf file was given to us by the client, and is basically a video converted to swf. However, it doesn't loop. I need it to loop continously. It would loop great if it would just "loop"
Is there any script I could use to add to my current code that will make the swf loop.
ActionScript Code:
_root.createEmptyMovieClip("container", 1);
loadMovie("3.swf", "container");
container._x = 0;
container._y = 200;
I am using Flash mx
GD
Looping Through A Txt File & AttachMovie()
hey out there,
just read the tutorial at http://www.kirupa.com/developer/mx/externaldata.htm and it got me thinking...
i've gotta load of cd track listings i need to show. all the info is in text files, and i can format it to look like:
totalTracks=2
&trackInfo1=Square One
&trackFile1=01_Square_One.mp3
&trackInfo2=What If?
&trackFile2=what_if.mp3
i've been trying to use this actionscript to loop through each track and attach it to the stage:
Code:
stop();
loadText = new LoadVars();
loadText.load("cd1.txt");
loadText.onLoad = function() {
//count the number of tracks
arrayLength = this.totalTracks;
//each movie clip has to be offset
vertOffset = 55;
//loop through each value in the array
for (i=0; i<arrayLength; i++) {
//attach the clip
var tClip = this.attachMovie("trackInfoMc", "track"+i, this.getNextHighestDepth());
trace(tClip);
//set it's y position
tClip._y = vertOffset+(tClip._y+vertOffset)*i;
//set the txt inside the new mc to the current value
tClip.trackInfo.text = this.trackInfo[i];
tClip.trackFile.text = this.trackFile[i];
}
};
the final idea is to turn each loop into a click link that loads the mp3 into a media player - i need to get this working 1st!
at the moment, nothing appears on the timeline.
can anyone see what i'm doing wrong or am i approaching this the wrong way...
anything would be great!
many thanks,
jake
Looping External Mp3 File
hello all!
need some help figuring out how to make my external streaming mp3 file loop. I tried a few things but i'm having no luck. here is my code where everything works fine now minus the code for looping.
thanks for looking.
houston
playList = ["url"];
currentSong = 0;
maxSongs = playList.length -1;
function startStreaming(){
mp3 = new Sound();
mp3.loadSound(playList[currentSong], true);
mp3.onSoundComplete = function(){
currentSong ++;
if (currentSong > maxSongs){
currentSong = 0;}
delete mp3;
}
}
startStreaming();
stop();
stop();
Loading An .swf File Without It Looping?
Hi,
I enjoyed your tutorial on how to build an entire website from flash. The tutorial provided the information on how to load an .swf file by clicking on one of the menu buttons. The example in the tutorial used swf files that were only 1 frame in length.
I've done this for a site that I've created, however, when I load the .swf file it will continue to loop over and over again. The swf files I'll load are contain up to 80 frames and will continue to loop. How do I get them to not loop?
Thanks!
Ted
How Do You Stop SWF File From Looping
Hi all
Not sure if this has been posted before, but I have just started using flash and I have created a simple animation. However, when I test the movie or double click on the .swf file for it, it will play but then loop and play it again.
I was therefore wondering if anyone knew how to stop it from looping. I have already tried inserting keyframes at the end of the movie with the stop option, it doesn't stop it from looping.
Thanks
Problems Looping Wav File
I am trying to make a sound file loop x amount of times while my movie plays, I create a new layer and click in the first frame of it and then drag my wav file onto the stage.Then in properties I check START in the sync options and loop is set to 10. No loop, does anybody know where i'm going wrong.
peace
Looping *.wav File - HELP Needed
Hi, I have problem looping wave file... I am unable to loop it infinitely and to make that seamless loop (no pause between loops, somehow like www.djisaac.com)...
If you can help, I would much appreciate (dunno what that means but sound like I would be thankful ^^) your help.
Looping A Sound File
can anyone tell me why flash adds silence to the beginning and at the end of my sound file. i have a mp3 file looped in sound forge. when import it into flash, it add silences.
why is this being done? and how can i fix this?
Variables From A Text File; Looping Vs. Go To
I've read a few of the tutorials that deal with reading variables from a text file. My problem is that in the ones i've read, it is always recommended to go to and play a particular frame (and then another and another perhaps), which will then check to see if all the variables have been loaded before proceeding to use them. I am new to flash, but experienced with director and lingo. I am a huge fan of sticking to one frame and having all the 'action' occur there through scripts. So attempting to load files, i run a loop to check for the final variable of my file, but unfortunately this loop slows flash and eventually freezes the program before uncovering any variables. Is there no other way but to use 'go to' in checking for my variables?
~julia using flashmx
Looping A Shorter Imported File?
Hi -
Obviously I'm pretty new at this.. I'm trying to figure out how to take a file that is, say, 30 frames total, and keep it looping throughout another movie which is not only much longer but starts and stops.
I'm hoping this is easy..
Thanks
Andrew
Stop A Swf File From Looping Eeep
i just want to know the simple command to stop the swf file from looping, and i dont need to know the html command because i know by going into file>publish settings>html it has a loop stop but thats just for the html content...
anyone,
thanks in advance
HELP Integrating Non-looping External FLV File
I have a slideshow. At the bottom of the stage is a scrolling array of thumbnails. When you click on one, the larger image (which is loaded externally) appears suddenly in a container in the black vacuum of the center of the stage.
This is where I am at now. It looks cool and kicks butt.
I need to have captions for each clip (as per instructions), and I want them to appear to the left of each image, vertically oriented. Then I had an idea:
Make an animation of a screw covering the text at the beginning and winding down to the bottom to reveal the text. I made the animation with Maya, which sucks compared to MAX, and made it into an FLV file.
Each time you click a thumbnail, the image loads AND I WANT the screw animation to play in a new container I made over the text (don't worry about the revealing-text part, yet. I was able to do this.
BUT IT WON"T STOP LOOPING.
Any help?
Download the files to work with yourself and post back to me, if you can. Source animation is copyrighted.
Problems Looping Swf File In Dreamweaver
Hi,
I have made a very simple banner comprised of jpgs transitioning into one another. Exported a swf file and used this file as the banner of a website. I want this banner to loop. I thought it was as easy as clicking *autoplay* to get it to start and *loop* to gt it to repeat, but that doesn't seem to be working.
Somehow it loops back to the first frame stops and goes white and stays white for ten seconds and then starts again at frame 1.
Any help would be much appreciated!
Help How To Stop Looping Loaded Swf File
Hi I’ve looked everywhere for a solution but I simply can't figure it out. Please help if you can, I'm new to flash and I’m coming up to a deadline where I’m am no where near finished thanks!
I'm making a character select menu and have buttons which load an external animated swf which shows a character profile within an empty movieclip.
I've placed the following code on the button
on (press) {
loadMovie("WB1.swf", "container");
Thing is the animation swf "WB1" loops, I've placed stop(); code at the end of the swf animation and even tried mc_WB1.stop(); as well as trying out placing the code in the character menu but no luck.
Any ideas or different approaches.
Thanks
Cs3 Help How To Stop Looping Loaded Swf File
Hi I’ve looked everywhere for a solution but I simply can't figure it out. Please help if you can, I'm new to flash and I’m coming up to a deadline where I’m am no where near finished thanks!
I'm making a character select menu and have buttons which load an external animated swf which shows a character profile within an empty movieclip.
I've placed the following code on the button
on (press) {
loadMovie("WB1.swf", "container");
Thing is the animation swf "WB1" loops, I've placed stop(); code at the end of the swf animation and even tried mc_WB1.stop(); as well as trying out placing the code in the character menu but no luck.
Any ideas or different approaches.
Thanks
[CS3] Pausing A Streaming FLV File Before Looping
//set screen of Flash Player
fscommand("fullscreen", true);
fscommand("allowscale", false);
fscommand("showmenu", false);
//load and loop sound
_root.createEmptyMovieClip("holder",1);
var sound_1:Sound = new Sound(holder);
sound_1.loadSound("atmosphere.mp3",true);
sound_1.onSoundComplete = function() {
sound_1.start(0,999);
};
//load Video
myNetconnection = new NetConnection();
myNetconnection.connect(null);
stream_ns = new NetStream(myNetconnection);
videoFrame.my_video.attachVideo(stream_ns);
stream_ns.play("video1.flv");
//Problem. I want the flv file to pause for 5 seconds before it repeats.
var timeInt:Number = setInterval(checkPauseTime, 5000, stream_ns);
function checkPauseTime():Void {
if (stream_ns.time == 33) { //the flv file runs for 33 seconds
stream_ns.pause();//not sure if this is correct.
clearInterval(timeInt);
}
}
//repeat Video
stream_ns.onStatus = function(info) {
if (info.code == "NetStream.Play.Stop") {
stream_ns.seek(0);
}
}
Looping An External Audio File
Hello all ,I know how to laod external audio file with action script ,but realy I need to loop that external file without importing it to the flash file ,would you please help me which action script should I use .
I appreciate you .
Sincerely yours Mohsena
Keeping Swf File From Looping With Stop ()
Hi there. I’m working with a Flash movie (about 9 MB) and I want to keep the file from looping indefinitely. I’ve learned that I would need to insert a key frame at the end of the movie and after highlighting the new key frame insert stop () action script.
It does the trick and the movie won’t loop anymore.
But now the movie is twice the size, which entails a whole new set of issues.
Is there another way? Where did I go wrong? Why is that?
I’m obviously a novice when it comes to Flash and I’m learning as I go. So any ideas and pointers would be greatly appreciated. Thanks.
Looping An Existing SWF File With No Source
I have a swf file but not the original source. As a novice to Flash, is it possible to cause the swf file to loop. At the moment it is embedded in an HTML file and I noticed that there is a parameter called Loop. However, setting this to true makes no difference. The movie still stops and does not loop back to the beginning.
Your help would be much appreciated!
Clive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: FAQ102-5096
|