5 Replies - 1379 Views - Last Post: 12 April 2011 - 11:35 AM

#1 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Update a dynamic text field while a sound clip plays

Posted 10 April 2011 - 12:46 PM

Hi

I have created a dynamic text field that counts down 20 seconds while a sound clip plays.
The count down worked when the code was inside its own movieclip along with the play, pause, stop buttons.
I am now trying to use instance names and put all code on the main timeline rather that on the
sound's play, pause, stop buttons.
When I test the movie I can see the dynamic text field containing a zero, and the sound clip plays,
but the countdown remains at zero.
I'm sure it has something to do with this part of the code!

textHolder.tf_description.text = this.firstSound.position/1000;

this.createEmptyMovieClip("textHolder", this.getNextHighestDepth());
textHolder.createTextField("tf_description", this.getNextHighestDepth(), 0, 0, 180, 100);
this.textHolder._visible = false;

textHolder.tf_description.border = true;
textHolder.tf_description.borderColor = 0xffffff;
textHolder.tf_description.background = true;
textHolder.tf_description.backgroundColor = 0xF64600;
textHolder.tf_description.wordWrap = true;

var descFmt:TextFormat = new TextFormat ();
descFmt.size = 100;
descFmt.color = 0xffffff;
descFmt.leftMargin = 15;
descFmt.rightMargin = 15;
descFmt.font = "Arial";
descFmt.align = "center";

firstSound = new Sound(firstSoundMc);
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);
this.onEnterFrame = function () {
	if (stopped!=true) {	
	textHolder.tf_description.text = this.firstSound.position/1000;   
textHolder.tf_description.setTextFormat(descFmt);
}
}

_root.main1.sound1play.onPress = function(){
	firstSound.start(0,0);
	textHolder._visible = true;
	}


Best Regards [email protected]

Is This A Good Question/Topic? 0
  • +

Replies To: Update a dynamic text field while a sound clip plays

#2 chinchang   User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 727
  • Joined: 22-December 08

Re: Update a dynamic text field while a sound clip plays

Posted 10 April 2011 - 01:37 PM

Replace
textHolder.tf_description.text = this.firstSound.position/1000;


with
textHolder.tf_description.text = "test";


Does it change ?
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Update a dynamic text field while a sound clip plays

Posted 10 April 2011 - 04:32 PM

Hi


No, I made the change and the text field continues to display zero!

Best Regards [email protected]
Was This Post Helpful? 0
  • +
  • -

#4 chinchang   User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 727
  • Joined: 22-December 08

Re: Update a dynamic text field while a sound clip plays

Posted 11 April 2011 - 03:44 AM

And its most probably because you might not be referencing the sound properly.

Try this line instead :
textHolder.tf_description.text = this.firstSound + "";



If its shows something then fine, else you are not referencing the sound properly.
Was This Post Helpful? 0
  • +
  • -

#5 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Update a dynamic text field while a sound clip plays

Posted 11 April 2011 - 04:42 PM

Hi
When I press the play button the sound plays and the dynamic text field displays.
The onSoundComplete is also working the photo1.jpg appears when the sound finishes.

_root.main1.sound1play.onPress = function(){
	firstSound.start(0,0);
	textHolder._visible = true;
	_root.main1.sound1play.enabled = false;
	_root.main2.sound2play.enabled = false;
	}
this.firstSound.onSoundComplete = function(){
	textHolder._visible = false;
	loadMovie("images/photo1.jpg", _root.empty1);
	_root.main1.sound1play.enabled = true;
	_root.main2.sound2play.enabled = true;
}

I tried your suggestion with no luck
I also tried

textHolder.tf_description.text = trace("testing");

Noththing showed in output.

As far as I know the only other way to create the sound object is to
leave out the name of the movieclip, which I tried, still nothing!

firstSound = new Sound();
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);
this.onEnterFrame = function () {
	if (playing==true) {	
textHolder.tf_description.text = trace("testing");
    textHolder.tf_description.setTextFormat(descFmt);
}
}

Was This Post Helpful? 0
  • +
  • -

#6 [email protected]   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 23-March 11

Re: Update a dynamic text field while a sound clip plays

Posted 12 April 2011 - 11:35 AM

Hi
I have found a different way to count down the seconds in my dynamic text field .
When the code bellow is run for 5 seconds the dynamic text field shows the number 5
I'm sure I can link the count down with the playing sound
by placing the interval variable inside of this line, although I'm not sure of the proper syntax.

textHolder.tf_description.text = this.firstSound.position/1000;


this.createEmptyMovieClip("textHolder", this.getNextHighestDepth());
textHolder.createTextField("tf_description", this.getNextHighestDepth(), 50, 0, 180, 100);
this.textHolder._visible = true;

textHolder.tf_description.border = true;
textHolder.tf_description.borderColor = 0xffffff;
textHolder.tf_description.background = true;
textHolder.tf_description.backgroundColor = 0xF64600;
textHolder.tf_description.wordWrap = true;

var descFmt:TextFormat = new TextFormat ();
descFmt.size = 100;
descFmt.color = 0xffffff;
descFmt.leftMargin = 15;
descFmt.rightMargin = 15;
descFmt.font = "Arial";
descFmt.align = "center";

var interval:Number = 5;
var startTime:Number = getTimer();

firstSound = new Sound(firstSoundMc);
firstSound.attachSound("sound1");
myMusicVolume=100;
firstSound.setVolume(myMusicVolume);
this.onEnterFrame = function() {
	var currentTime:Number = getTimer();
	if (currentTime>=startTime+(interval*1000)) {
		delete this.onEnterFrame;
		textHolder.tf_description.text = interval;
    textHolder.tf_description.setTextFormat(descFmt);
		trace(interval+" seconds have elapsed");
	}
};



Best Regards [email protected]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1