[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Selecting text in dynamic text box for linking

Posted on 2008-06-21
9
Medium Priority
?
338 Views
Last Modified: 2013-11-11
I have a dynamic textbox that pulls from an XML file.  Is there a way I can have my code search the dynamic text box for certain words, like "Sarah", and change the color of the word and have it gotoAndPlay a certain keyframe when clicked on?
0
Comment
Question by:walker6o9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
9 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 21839877
follwoing two function will do the work:

I have also attached a working sample which will help to understand how actually these function can be used.

function setupTextField(txtInst, wordToSearch, gotoFrame) {
	var txt = txtInst.text;
	var wordLength = wordToSearch.length;
	var index = txt.indexOf(wordToSearch);
	if (index == -1) {
		return;
	}
	var linkTxt = '<a href="asfunction:gotoFunction,'+gotoFrame+'"><font color="#FF0000">'+wordToSearch+'</font></a>';
	var prefixTxt = txt.substring(0, index);
	var suffixTxt = txt.substring(index+wordLength, txt.length);
	txtInst.html = true;
	txtInst.htmlText = prefixTxt+linkTxt+suffixTxt;
	//trace(txt.htmlText);
}
function gotoFunction(frame) {
	gotoAndPlay(frame);
}

Open in new window

color-and-link-a-part-of-txt.fla.txt
0
 
LVL 1

Author Comment

by:walker6o9
ID: 21850603
Is there a way to mod the setupTextField function slightly so that the gotoFunction includes a second parameter, like so:

function gotoFunction(frame, wordToSearch)
{
upcomingFrameVariable = wordToSearch
gotoAndPlay(frame)

}
0
 
LVL 1

Author Comment

by:walker6o9
ID: 21851364
Also, I'm having a really weird problem.  I used your code to select certain words from a textField generated by an XML file.  But when I include a link in the XML text (using CDATA and setting html = true and the textfield to htmlText, I made sure these weren't the problem), it no longer allows me to click on the link.  When I stop using the setupTextField function, the links works again.  Do you know why the function kills the html link, or, more important, how to fix this?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:walker6o9
ID: 21851524
Actually, I fixed the problem I listed above, and its working fine.  

Except that it only does the once for the word.  Is there a way to mod this so that that it picks up all instances of the word in the text if it appears more than once?
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 2000 total points
ID: 21852256
Below is the updated code, which makes all occurance of mentioned text into Link and also passes frame and word to the gotoFunction


stop();
//
myText.text = 'this text includes Sarah and Sarah again and again one more time Sarah';
setupTextField(myText,'Sarah',20);
 
 
function setupTextField(txtInst, wordToSearch, gotoFrame) {
	var txt = txtInst.text;
	var wordLength = wordToSearch.length;
	var index = txt.indexOf(wordToSearch);
	if (index == -1) {
		return;
	}
	var linkTxt = '<a href="asfunction:gotoFunction,'+gotoFrame+'~~'+wordToSearch+'"><font color="#FF0000">'+wordToSearch+'</font></a>';
	txt = txt.split(wordToSearch).join(linkTxt);
	txtInst.html = true;
	txtInst.htmlText = txt;
	//trace(txt.htmlText);
}
function gotoFunction(param) {
	var frame = param.split('~~')[0];
	var upcomingFrameVariable = param.split('~~')[1];
	trace(frame+":"+upcomingFrameVariable);
	gotoAndStop(frame);
}

Open in new window

0
 
LVL 1

Author Comment

by:walker6o9
ID: 21858125
If I run that for two words in the field, it only works for the last word.

setupTextField(myText,'Sarah',20);
setupTextField(myText,'again',20);


Only again shows up.
0
 
LVL 1

Author Comment

by:walker6o9
ID: 21858186
Nevermind, I got it solved.  If you declare txt outside the function, return it, and then run it through away, it works for multiple words.

0
 
LVL 1

Author Closing Comment

by:walker6o9
ID: 31469453
Very helpful.  Thank you so much.
0
 
LVL 1

Author Comment

by:walker6o9
ID: 21879773
So, this is working fine, but only if the dynamic textbox is on the frame.  If the dynamic textbox is inside a movie clip (or inside a movie clip inside a movie clip, as i have it), the text still changes colors, and the mouse changes to onRollOver state like it does for the other links, but when I click, nothing happens.  However, the links that were embedded from the XML still work.  I put a trace in the gotoFunction(), and it isn't even being read.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to record live broadcast.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question