Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Actionscript Dynamic Text Links 1

Status
Not open for further replies.

jalbertson

Technical User
Feb 8, 2007
32
US
Ok I have a very basic if/else statement. I am wanting to know how to make a link say one thing, Like Not old enough! or You are Old enough. and depending on what answer you get it takes you to one of two different websites. I am listing my code to see if anyone has any ideas.

Code:
if (entry < 21) {
	answer.text = "Not Old Enough!";
	answer.onPress = getUrl("[URL unfurl="true"]http://www.yahoo.com/",[/URL] "_self");
	answer.textColor = "0xFF0000"
} else {
	answer.text = "You are Old Enough!";
	answer.onPress = getUrl("[URL unfurl="true"]http://www.google.com/",[/URL] "_self");
	answer.textColor = "0x0000FF"
}

Thanks in advance!
 
One way is to use HTML text:
Code:
...
answer.html = true;
answer.htmlText = "<a href='[URL unfurl="true"]http://www.yahoo.com/'>Not[/URL] Old Enough!</a>";
answer.textColor = 0xFF0000;
...
By the way "textColor" is a Number, not a String.

Kenneth Kawamoto
 
I did what you said, and the text will no longer populate in the dynamic text field. So, there is no link. Maybe I applied it wrong or something...

Code:
if (entry < 21) {
	answer.html = true;
	answer.htmlText = "<a href='[URL unfurl="true"]http://www.yahoo.com/'>Not[/URL] Old Enough!</a>";
	answer.textColor = 0xFF0000;
} else {
	answer.html = true;
	answer.htmlText = "<a href='[URL unfurl="true"]http://www.google.com/'>You[/URL] are Old Enough!</a>";
	answer.textColor = 0xFF0000;
}
 
The script is definitely correct. You can verify it with a blank FLA with the following:
Code:
var entry:Number = 21;
var answer:TextField = createTextField("answer", 1, 10, 10, 100, 1);
with (answer) {
	autoSize = true;
}
//
if (entry<21) {
	answer.html = true;
	answer.htmlText = "<a href='[URL unfurl="true"]http://www.yahoo.com/'>Not[/URL] Old Enough!</a>";
	answer.textColor = 0xff0000;
} else {
	answer.html = true;
	answer.htmlText = "<a href='[URL unfurl="true"]http://www.google.com/'>You[/URL] are Old Enough!</a>";
	answer.textColor = 0x0000ff;
}

Kenneth Kawamoto
 
I guess it is something with the first frame of my project but I do not know what it is. Is there any way I can email you the file, and have you take a look at it.
 
or is there any way I can upload it here for you to look at.
 
There is a couple of issues with your movie.

First the variable "entry" is not defined anywhere. Name your Input TextField as "input", then add a line to your button script so that it now reads:
Code:
on (release) {
	entry = parseInt(input.text);
	gotoAndPlay("resultspage");
}
Secondly delete "answer" TextField and create a new one and name it "answer" - there's something wrong with the existing one!


Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top