# On(rollover) change dynamic text how to?

**URL:** <https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801>\
**Category:** Uncategorized\
**Created:** [May 8, 2008, 8:04pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801 "2008-05-08T20:04:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)\
**Post date:** [May 8, 2008, 8:04pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801/1 "2008-05-08T20:04:43Z")

</div>

I have several buttons(its a map project) with several country maps.  
I would like to on rollover to have the name of country to change.

I tried this:

1. created a dynamic text field called “txtfield” and placed it strategically where I want the text to appear and change based on the map selected/rolled over.

2. I have added the following script to the button:  
on(rollover) {  
txtfield.txt = “IRAQ”;  
}

it did not work…

what do I do wrong, please.

---

<div class="post-metadata">

**Author:** ![findAll](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@findAll](https://forum.kirupa.com/u/findAll)\
**Post date:** [May 8, 2008, 10:09pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801/2 "2008-05-08T22:09:47Z")

</div>

first, it shouldn’t be

```auto

 txtfield.txt = "IRAQ";

```

but

```auto

  txtfield.text = "IRAQ";

```

so it is “text” after the dot, not “txt”; and second, I suggest to put the code for the buttons in the timeline, not attached directly to the buttons; I mean you have to give buttons instance names and then refer to them by actionscript in the timeline, like:

```auto

myButtonInstanceName.onRollOver = function(){
txtfield.text = "IRAQ"
}

```

cheers…

---

<div class="post-metadata">

**Author:** ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)\
**Post date:** [May 9, 2008, 12:23pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801/3 "2008-05-09T12:23:25Z")

</div>

Thank you, thank you, exactly… it worked… now similar question

how to change the image using the same method:

1. createa place holder for the image(how) and then use same process to have it changed???  
could you pleas help a bit more.  
I wil appreciate it.

thank you

---

<div class="post-metadata">

**Author:** ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)\
**Post date:** [May 9, 2008, 12:29pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801/4 "2008-05-09T12:29:19Z")

</div>

iraq.onRollOver = function(){  
txtfield.text = “IRAQ”;  
mctrans.image = “flag\_iraq.jpg”;  
}  
iraq.onRollOut = function(){  
txtfield.text = “”;  
mctrans.image = “”;  
}

I know it is wrong…

I created an empty movie clip, named it in the properties window for AC as “mstrans”

I was hoping to have it working, obviously – I failed.

---

<div class="post-metadata">

**Author:** ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)\
**Post date:** [May 9, 2008, 1:01pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801/5 "2008-05-09T13:01:51Z")

</div>

ok, i figure it out:

1. open library and drag the Loader component onto the stage.
2. give it a AC name “mc\_loader”
3. in the action layer add these(in blue)

iraq.onRollOver = function(){  
txtfield.text = “IRAQ”;  
[COLOR=“Blue”]mc\_loader.contentPath = “flag\_iraq.png”;[/COLOR]  
}  
iraq.onRollOut = function(){  
txtfield.text = “”;  
[COLOR=“Blue”]mc\_loader.contentPath = “”;[/COLOR]  
}

---

<div class="post-metadata">

**Author:** ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)\
**Post date:** [May 9, 2008, 1:57pm UTC](https://forum.kirupa.com/t/on-rollover-change-dynamic-text-how-to/259801/6 "2008-05-09T13:57:17Z")

</div>

if your files are located in the diferent folders then:

[COLOR=“Blue”]mc\_loader.contentPath = “foldername/flag\_iraq.png”;[/COLOR]
