Skip to main content
Known Participant
June 21, 2009
Answered

Setting text in a dynamic text field

  • June 21, 2009
  • 2 replies
  • 716 views

Hi,

I'm having difficulty setting the text of a dynamic text field when using an if statement.

I have a gallery and thumbnails, which gives each image a picNum, ie 1, 2 etc;

When I click on the thumbnails, it sets the picNum accordingly.

What I want to do is set the caption depending upon my picNum, so I set a function to change the caption depending upon the picNum that is called when the thumbnail is clicked.  Ie.

caption = function() {

     if(picNum=1) {_root.caption.text = "image 1 caption"};

     if(picNum=2) {_root.caption.text = "image 2 caption"};

}

I tried putting else if, but I got an error.

My problem is that it doesn't change the caption being displayed when the picNum meets the criteria.  Something is obviously going wrong here, but not being great at actionscript, I don't know where I am going wrong.  The above code is a basic example of what I'm trying to do.  I've attached the actual file to show you what I'm trying to do. (Using Flash MX, publishing to Flash Player 6)

Any help would be really appreciated.

Thanks

This topic has been closed for replies.
Correct answer Ned Murphy

= is used for equating something to something

== is used for comparing something to something...    if(picNum==1)

2 replies

Inspiring
June 21, 2009

You are using assignment "=" and not conditional "==".

But here is a neat thing called a switch. If you have more than a couple conditions it is a sweet way to go and to my eye, at least, much easier to read and maintain:

var str:String;

switch(picNum){

case 1:

str="Image 1 caption";

break;

case 2:

str="Image 2 caption";

break;

default:

str="Don't know what caption that is supposed to be.";

}

_root.caption.text=str;

Known Participant
June 21, 2009

Thanks both for your help on this .

Just another quick query about the dynamic text field.  When I test my movie, it doesn't display my text in the font that the textbox is set to.  It retains all of the other formatting, eg colour, but the font is changing.  Any ideas why?

Ned Murphy
Legend
June 21, 2009

Try embedding the font in textfield.  There should be a provision for it in the Properties panel when you select the textfield.

Ned Murphy
Ned MurphyCorrect answer
Legend
June 21, 2009

= is used for equating something to something

== is used for comparing something to something...    if(picNum==1)