View Full Version : Changing dynamic text content with button click
artlass
08-14-2009, 01:13 PM
I think this must be the simplest use ever,
but have scoured the net for my answer to no avail!
enough excusing,
my flash page is simple,
I have created a dynamic text box with the variable and the instance name
"colourname"
and in the first frame of my movie have
//set up dynamic text box
var thistext:String = "Name of Colour";
colourname.text = thistext;
i have different coloured buttons, and when the user clicks on the button it changes a certain image, and I want it to change the text in the dynamic text box, so I have put:
this.mybutton.onRelease = function () {
colourname.text = "Red"}
This works well on the first click, but refuses to change on any future click.
Also on initially on playing the movie the text displays "level_0.colourname" which is something I don't quite understand either.
Thankyou so much to anywonder who can help me out, I have been scouring the net and still understand not!
rholdrae
08-15-2009, 03:42 AM
can you upload your source?
artlass
08-15-2009, 11:46 AM
Very happy to, the .fla.zip is too big to upload, so I have tried to summarise here, tell me if you need more info
In the timeline, in the first frame I have this:
//set up dynamic text box
var thistext:String = "Hello there!";
colourname.text = thistext;
on the stage I have the dynamic text box named "colourname"
on the stage I also have movieclips "cloth1" up to "cloth6" inside "sidetable" (a MC).
these "cloth" MCs are used as buttons to load external images into "reflection_mc". All this works perfectly, giving the following orders:
this.sidetable.cloth1.onRelease = function () {
mirror_mc.reflection_mc.loadMovie("images/FrillR.jpg")
colourname.text = "Red & Black"}
The last line shows what I want to do; load a short description of the image.
This works fine the first time, but when other "cloth" buttons are clicked the text does not change.
To get a visual idea of the page, it is at www.houseof.intirka.net, and it is the "collection" page
Otherwise I can send you the .fla some other way if you like.
thankyou infinitely already, you have given me hope!
rholdrae
08-17-2009, 07:30 AM
Hi, sorry if it took me 2 days to reply cause I forgot to subscribe on this thread.. Anywayz, I tried the code you posted and its working fine. I assume you're code is something like this...
this.sidetable.cloth1.onRelease = function () {
mirror_mc.reflection_mc.loadMovie("images/FrillR1.jpg")
colourname.text = "Red & Black"
}
this.sidetable.cloth2.onRelease = function () {
mirror_mc.reflection_mc.loadMovie("images/FrillR2.jpg")
colourname.text = "Blue & Black"
}
// up to cloth6?
cause aside from not seeing your code for the other buttons, I can't replicate your problem. But here's what I did...
var btnarr:Array = new Array("cloth0","cloth1","cloth2","cloth3","cloth4","cloth5","cloth6");
var msgArr:Array = new Array("Red & Black","White & Black","Green & Black","Blue & Black","Yellow & Black","Orange & Black","Gold & Black");
var imgArr:Array = new Array("images/FrillR1.jpg","images/FrillR2.jpg","images/FrillR3.jpg","images/FrillR4.jpg","images/FrillR5.jpg","images/FrillR6.jpg")
onEnterFrame = function(){
for(a=0; a<btnarr.length; a++){
var cloth:MovieClip = sidetable["cloth"+a];
cloth.onRelease = function () {
for(b=0; b<btnarr.length; b++){
if(btnarr[b] == this._name){
mirror_mc.reflection_mc.loadMovie(imgArr[b])
colourname.text = msgArr[b];
}
}
}
}
}
Tell me if it works...
artlass
08-17-2009, 02:35 PM
its all very exciting,
I wonder if I can send you my .fla via some other means (as i said it is too big for here)... because I am wondering where exactly to put the code you wrote.
The thing is that for each item of clothing there are different images and different colour names to display, and seeing as I am quite beginnery, I have just put everything on the same timeline
So I am wondering how to make the array differentiate between the different items, should I just repeat your script on each keyframe or should I transform all the different items into movieclips of their own...
If you understand my question great, if not, I am way off track and would love for you to see the .fla...
thanks so much for your brain work!
Artlass
artlass
08-17-2009, 02:50 PM
Sorry, was typing to you while I should have been experimenting more...
have indeed put your script at each keyframe(ie item of clothing), and works great to call up the images , such neater scripting!
However the word problem stays the same:
when the page appears the text box displays the text:" level_0.colourname"
and when you click on the first "cloth"button it displays the correct word in the box, but after that the word does not change when you click on the other cloth buttons.
It doesn't matter which cloth button you choose to press first; it will call up the correct text for that image, so it is reading the array correctly, but it won't change after that... hmmm
what are your thoughts?
artlass
rholdrae
08-20-2009, 02:36 AM
Hi pal, how's it going? Sorry for the late reply, I've been so busy lately. I think it's more convinient for both of us if you could send your fla. You can send it via rapidshare or other file hosting site.
rholdrae
08-20-2009, 06:55 AM
Where did you put the code? Is it inside a movie clip? Is your textfield colourname in the root? If you put the code inside the movie clip and your textfield is in the root, try
_root.colourname.text = msgArr[b];
if not I really need to see your file... I'm happy to help. Anyway here's a sample file that I made.
artlass
08-20-2009, 02:54 PM
thanks so much for your continuing help, it is greatly appreciated...
I have managed to upload the .fla, Because after admiring how well your beautiful sample worked, I played around with placing the script in different places, but can't get it to work any better than last time.
have put all the blah blah in the txt file, cause there are a few other peculiarities...
Action script sure keeps you active!
rholdrae
08-21-2009, 12:21 PM
yo man! I've seen your file,. the problem is that you used a different font for your dynamic text colourname. I don't know how to deal with it cause honestly I'm new also in flash and actionscript. I just want to extend everything I've learned from people here in this forum... if you use a normal dynamic text or input text as colourname it will work properly.
next issue about your buttons, I wasn't expecting that your using 6 buttons separately so I put cloth0 to 5. Since I used it in a for loop which means it started from 0 and ends to 5. in your case notice these comments
var btnarr:Array = new Array("cloth1","cloth2");// your names started at 1
var msgArr:Array = new Array("Red & Black","Teal & Black");
var imgArr:Array = new Array("images/FrillR.jpg","images/FrillB.jpg")
onEnterFrame = function(){
for(a=0; a<btnarr.length; a++){ // our for loops started at 0
//var cloth:MovieClip = sidetable["cloth"+a]; you added "a" which is 0 so the name will be cloth0 and cloth1
//should be
//var num = a+1;
//var cloth:MovieClip = sidetable["cloth"+num];
//but if your going to use it in your different frame and you are using
//let say cloth3 and cloth6 for example... using for loop concatanating it
//with variable "a" won't work. cause again it starts with 0
// so this is how we're going to handle it
var cloth:MovieClip = sidetable[btnarr[a]]; // this will get the trick
// btnarr[0] = cloth1 or cloth3
// btnarr[1] = cloth2 or cloth6
cloth.onRelease = function () {
for(b=0; b<btnarr.length; b++){
if(btnarr[b] == this._name){
mirror_mc.reflection_mc.loadMovie(imgArr[b])
_root.colourname.text = msgArr[b];
}
}
}
}
}
I hope this helps. By the way, if you find out how to deal with the input text issue please post it here, I'll much appreciate it.. or I hope someone experienced will help... :)
artlass
08-25-2009, 11:22 AM
hey , thanks for the reply... I will try and figure out about the font and let you know....
For the buttons I tried one version of the .fla with the code you masterminded, and 1 version with changing the buttons names to be cloth0-5...that sorted out the button issue
I also changed the font to a more normal font,
but it did not change anything with the colourname appearing;
I still get the "level0_colourname" appearing at the beginning, and then it will change on the first click (to eg. "red and black") but after that refuses to change again...
did you get it to work?
if so could you send me the .fla that I might study it?
Thanks a lot....
I am wondering is I shouldn't put all the clothing into movie clips... hmmm,
thanks so much, and would love to hear what you think,
artlass
rholdrae
08-25-2009, 11:30 AM
well you could try this. copy my input text from the sample I've posted and replace it with your input text. you should delete your original input text on the stage and use the code above. as far as I can remember that's what I did or you could simply delete your original input text and create a new input text box. tell me if it didn't work then I'll send a new file.
artlass
08-25-2009, 02:16 PM
genius! just swapping the old text box worked
thanks so much, will now try and study more about these font problems, let you know if I find a way around it!
thanks again, you've saved my day!
rholdrae
08-25-2009, 06:04 PM
You are more than welcome, I'm glad I was able to help.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.