# Random fading text?

**URL:** https://forum.kirupa.com/t/random-fading-text/57492
**Category:** Uncategorized
**Created:** [July 13, 2004, 7:12pm UTC](https://forum.kirupa.com/t/random-fading-text/57492 "2004-07-13T19:12:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gavinl](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gavinl](https://forum.kirupa.com/u/gavinl)
#### Post date: [July 13, 2004, 7:12pm UTC](https://forum.kirupa.com/t/random-fading-text/57492/1 "2004-07-13T19:12:14Z")

</div>

Hi all,

I did a fading text background for a frame page and would also like to have the text appear randomly.

So far I’ve only read about doing random motion of objects in FMX, anyone can help me with doing random static appearances of fading text?

fla attached

TIA! 🍺

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 14, 2004, 9:52am UTC](https://forum.kirupa.com/t/random-fading-text/57492/2 "2004-07-14T09:52:10Z")

</div>

heya, this is pretty simple.  
put your phrases as static text as different frames in a movieclip called _staticPhrases_ and now for the code to go with it:

```auto
staticPhrases.gotoAndStop(Math.ceil(Math.random()*x))

```

where x = the number of frames/phrases in your mc _staticPhrases_… you can also uses a similar method with an array but for this you needa dynamic text box… which as i understand it is not what you want…

ifu have ne probs, plz feel free to post as i dont have FMX here…

Prophet.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 14, 2004, 6:28pm UTC](https://forum.kirupa.com/t/random-fading-text/57492/3 "2004-07-14T18:28:22Z")

</div>

Hi Prophet, thanks for your tip.

I don’t quite get what you meant by “put your phrases as static text as different frames in a movieclip called staticPhrases”. How can I get the text to relocate randomly yet retaining the fading motion tween?

Thanks again! 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 14, 2004, 9:53pm UTC](https://forum.kirupa.com/t/random-fading-text/57492/4 "2004-07-14T21:53:58Z")

</div>

oh right you want random locations!!  
sorry, i thought you meant you had several different phrases that you wanted it to choose from randomly…  
ok so im gonna go ahead and assume you want just the one phrase then… ok… lets say you want your text to appear within the bounds of a box with xy points at (150,150), (300,300)

ok.  
first things first… you cant set the position of a text field. so put your text field into a movieclip. this movie clip shall have an instance name of _textMC_. if you have tweens then make sure it all works with this inside a movieclip NOW… work out any bugs if they do occur…

next, create a function to call to change the location of your movie clip…

```auto
function moveMC(){

```

and now for the actual code:

generate random values for its x and y position…

```auto
x = Math.random()
y = Math.random()

```

now this generates a random number between 1 and 0 which we now need to maipulate to get a number between 150 and 300.

difference of 150 and 300 : 300-150=150  
hence:

```auto
x = (x*150)+150
y = (y*150)+150

```

now we simply apply these values to our movieclip:

```auto
textMC._x = x
textMC._y = y

```

and ending the function…

```auto
}

```

and then all u have to do is call the function wenever you want it moved! (ie. at a certain frame of a tween, like wen it has faded to complete transparency…)

hope i didnt miss anything out… and also hope u could understand it!! 😛

regards,

Prophet.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 14, 2004, 10:11pm UTC](https://forum.kirupa.com/t/random-fading-text/57492/5 "2004-07-14T22:11:50Z")

</div>

yokey doke, i just got a round to opening ur fla…  
ur texts are already in movieclips… you just need to assign them instance names (in the property inspector) to be used within the function… a suggested workaround is this… you name each movieclip sumthing like _Rtext1; Rtext2; Rtext3_ etc… and then on each frame set variable _i_ equal to the appropriate number before you call the function and rather than the line

```auto
textMC._x = x
textMC._y = y

```

with

```auto
this["Rtext"+i]._x = x
this["Rtext"+i]._y = y

```

bear in mind ive used the _this_ prefix meaning that the code would have to be placed on the same level as your movieclips… which in your flas would actually just be the root level anyway…

sidenote1: when working with functins you only need to define it once to address it several times  
sidenote2: the \_x and \_y values will work on the registration points of the targeted mc

Prophet.

PS hope i make sense 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 15, 2004, 5:28pm UTC](https://forum.kirupa.com/t/random-fading-text/57492/6 "2004-07-15T17:28:49Z")

</div>

Thanks again your Prophet-ness 😉

I’ll try and feedback once I’m through with it

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 16, 2004, 8:21am UTC](https://forum.kirupa.com/t/random-fading-text/57492/7 "2004-07-16T08:21:17Z")

</div>

lol only tryin to help mate 😉

Prophet.
