• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Flash 8 Dynamic Textfield

I have created a Flash photo slideshow that uses an xml file to populate the show, I have added a text field to show the image name but it only populates on the first photo, when I click the next button or allow the timer to switch photos the text field does not update.  I am using the textvariable.text = picArray[currentElement]; in the init() function and again in the nextpic() function which is called during the timed picture change and on the button press.  I am new to actionscript but I thought this would be a simple task please help!
0
chetweewax
Asked:
chetweewax
  • 4
  • 3
1 Solution
 
asaivanCommented:
Can you post more of your code?
0
 
chetweewaxAuthor Commented:
Here is all the code
import mx.transitions.Tween;
import mx.transitions.easing.Strong;
 
this.createEmptyMovieClip("container2_mc",this.getNextHighestDepth());
this.createEmptyMovieClip("container1_mc",this.getNextHighestDepth());
this.createEmptyMovieClip("buttons_mc",this.getNextHighestDepth());
this.attachMovie("loader","loader_mc",this.getNextHighestDepth());
loader_mc._x = (Stage.width - loader_mc._width)/2;
loader_mc._y = (Stage.height - loader_mc._height)/2;
container1_mc._x = 0;
container1_mc._y = 0;
container2_mc._x = 0;
container2_mc._y = 0;
 
var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myMCL.addListener(myListener);
 
myListener.onLoadProgress = function(target,bytesLoaded,bytesTotal) {
	loader_mc._alpha = 100;
	var pct = Math.round(bytesLoaded/bytesTotal*100);
	loader_mc.bar_mc._xscale = pct;
}
 
myListener.onLoadComplete = function(target) {
	loader_mc._alpha = 0;
	fadeIn();
}
 
buttons_mc.attachMovie("prev","prev_mc",buttons_mc.getNextHighestDepth());
buttons_mc.attachMovie("next","next_mc",buttons_mc.getNextHighestDepth());
buttons_mc.attachMovie("play","play_mc",buttons_mc.getNextHighestDepth());
buttons_mc.attachMovie("pause","pause_mc",buttons_mc.getNextHighestDepth());
buttons_mc.attachMovie("name_txt","name_mc",buttons_mc.getNextHighestDepth());
buttons_mc.pause_mc._visible = false;
 
buttons_mc.name_mc._x = 5;
buttons_mc.name_mc._y = 390;
 
buttons_mc.next_mc._x = ((Stage.width - buttons_mc.next_mc._width)/2) + 50;
buttons_mc.next_mc._y = Stage.height - buttons_mc.next_mc._height - 10;
 
buttons_mc.prev_mc._x = ((Stage.width - buttons_mc.next_mc._width)/2) - 50;
buttons_mc.prev_mc._y = Stage.height - buttons_mc.next_mc._height - 10;
 
buttons_mc.pause_mc._x = (Stage.width - buttons_mc.pause_mc._width)/2;
buttons_mc.pause_mc._y = Stage.height - buttons_mc.pause_mc._height - 3;
 
buttons_mc.play_mc._x = (Stage.width - buttons_mc.play_mc._width)/2;
buttons_mc.play_mc._y = Stage.height - buttons_mc.play_mc._height - 3;
 
//-------XML ------//
var myXML:XML = new XML();
myXML.ignoreWhite = true;
 
var picArray:Array = new Array();
var currentElement:Number = 0;
 
myXML.onLoad = function(success) {
	if (success) {
		var ss:Array = myXML.firstChild.childNodes;
		for (i=0;i<ss.length;i++) {
			picArray.push(ss[i].attributes.url);
		}
		init();
	}
	else
	{
		trace("XML could not load");
	}
}
 
myXML.load("cake.xml");
 
var currentContainer:MovieClip = container1_mc;
 
function init() {
	myMCL.loadClip(picArray[currentElement],container1_mc);
	buttons_mc.name_mc.namepic.text = picArray[currentElement];
}
 
buttons_mc.pause_mc.onRelease = function() {
	buttons_mc.play_mc._visible = true;
	buttons_mc.pause_mc._visible = false;
	clearInterval(myInterval);
}
 
buttons_mc.play_mc.onRelease = function() {
	buttons_mc.pause_mc._visible = true;
	buttons_mc.play_mc._visible = false;
	clearInterval(myInterval);
	myInterval = setInterval(nextPicture, 5000);
	nextPicture();
}
 
buttons_mc.next_mc.onRelease = function() {
	buttons_mc.pause_mc._visible = true;
	buttons_mc.play_mc._visible = false;	
	nextPicture();
	clearInterval(myInterval);
	myInterval = setInterval(nextPicture, 5000);
}
 
 
function nextPicture()
{
	if (currentContainer == container1_mc) {
		currentContainer = container2_mc;
	}
	else
	{
		currentContainer = container1_mc;
	}
	currentContainer._alpha = 0;
	container1_mc.swapDepths(container2_mc);
	if (currentElement < picArray.length-1) {
		currentElement++;
	}
	else
	{
		currentElement = 0;
	}
	
	buttons_mc.name_mc.namepic.text = picArray[currentElement];
	myMCL.loadClip(picArray[currentElement],currentContainer);
 
}
 
 
buttons_mc.prev_mc.onRelease = function() {
	buttons_mc.pause_mc._visible = true;
	buttons_mc.play_mc._visible = false;
	if (currentContainer == container1_mc) {
		currentContainer = container2_mc;
	}
	else
	{
		currentContainer = container1_mc;
	}
	currentContainer._alpha = 0;
	container1_mc.swapDepths(container2_mc);
	if (currentElement > 0) {
		currentElement--;
	}
	else
	{
		currentElement = picArray.length-1;
	}
	myMCL.loadClip(picArray[currentElement],currentContainer);
	clearInterval(myInterval);
	myInterval = setInterval(nextPicture, 5000);
}
 
function fadeIn() {
	new Tween(currentContainer,"_alpha",Strong.easeOut,0,100,36,false);
}

Open in new window

0
 
asaivanCommented:
Well, one thing I'm noticing is that you don't have myInterval declared outside of any code block.  I don't know if it's directly related to the problem, but in order to access the myInterval consistently as the same object, you'll need to declare it.  

var myInterval:Object;

Try this first.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chetweewaxAuthor Commented:
I get a type mismatch error if I add the var myInterval:Object;  The myInterval only has to do with the timer to change pictures automatically.  The text field does not update even on the click of the next button.
0
 
asaivanCommented:
Then untype the object.

var myInterval;

What do you get if you do:

trace ( buttons_mc.name_mc.namepic.text );

in the nextPicture function?  Is it changing?



0
 
chetweewaxAuthor Commented:
when I did a trace on buttons_mc.name_mc.namepic.text the image name was always the first picture.  I changed the buttons_mc.name_mc.namepic.text = picArray[currentElement]; to buttons_mc.name_mc.namepic = picArray[currentElement]; and ran another trace and the value changed as the pictures changed.  So it seems to be working now.
0
 
asaivanCommented:
ok, keep me posted
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now