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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BB style editor 1

Status
Not open for further replies.

MJB3K

Programmer
Joined
Jul 16, 2004
Messages
524
Location
GB
Is it possible to create a BB style editor in flash??

Say i had the text: Hello World and i selected it, would i be able to put <b></b> or anything around it if i click a button??

Any ideas??

Regards,

Martin

Computing Help And Info:
 
not quite sure what you want to do but this may get you started

this.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 300, 200);
my_txt.multiline = true;
my_txt.wordWrap = true;
my_txt.border = true;
my_txt.type = "dynamic";
my_txt.html = true
my_txt.htmlText = "Select some text here";
var my_cm:ContextMenu = new ContextMenu();
my_cm.customItems.push(new ContextMenuItem("Bold...", doBold));
function doBold():Void {
var startIndex:Number = Selection.getBeginIndex();
var endIndex:Number = Selection.getEndIndex();
var stringToBold:String = my_txt.text.substring(startIndex, endIndex)
stringToBold= "<b>"+stringToBold+"</b>"
my_txt.replaceText(startIndex, endIndex, stringToBold);
}
my_txt.menu = my_cm;

 
yeah, that works fine, but how can i do it so if i click a button on the stage, it calls that function and does the same thing?
Code:
btnBold.onPress = function(){
	_root.doBold();
}
I tried that, but it doesnt work...

Any ideas??

Regards,

Martin

Computing Help And Info:
 
code can be improved i am sure but this will work

this.createEmptyMovieClip("clip",this.getNextHighestDepth())
clip.createTextField("my_txt", this.getNextHighestDepth(), 0, 0, 300, 200);
clip.my_txt.multiline = true;
clip.my_txt.wordWrap = true;
clip.my_txt.border = true;
clip.my_txt.type = "dynamic";
clip.my_txt.html = true;
clip.my_txt.htmlText = "Select some text here";
clip.onEnterFrame = function(){
if(Selection.getFocus()=="_level0.clip.my_txt"){
startIndex = Selection.getBeginIndex();
endIndex = Selection.getEndIndex();
stringToBold = this.my_txt.text.substring(startIndex, endIndex);
}
};
boldBtn.onRelease = function(){
stringToBold = "<b>"+stringToBold+"</b>";
clip.my_txt.replaceText(startIndex, endIndex, stringToBold);
}
 
doesn't seem to work... because it seems when you click the button, the text loses focus, therefore its not selected.

Any other ideas of how to make it work?


^^ how do they get it to work??

Regards,

Martin

Computing Help And Info:
 
code above works just fine....to test just copy and paste into a blank fla and add a boldBtn to the stage
 
cheers, that works fine :)

Could you tel me how they would make something like that editor on flashblocks??


Regards,

Martin

Computing Help And Info:
 
well to actually make the text bold you have to remove the tags so add a function to do this

boldBtn.onRelease = function(){
stringToBold = "<b>"+stringToBold+"</b>";
clip.my_txt.replaceText(startIndex, endIndex, stringToBold);
removeTags()
}

function removeTags(){
tmp = clip.my_txt.text
clip.my_txt.htmlText = tmp
}

much the same for all other buttons that you want...just change the tags

add dropdows for font, font size etc.

the editor is not difficult to make just time consuming

 
this is not at the stage of the flashblocks editor but you can add as much or as little as you want to these things

as a quick exercise i put this one together this morning


i wont do any more to it as im bored with it but if the fla will help you then just say so and ill put it up for download

up to you how many bells and whistles you want to add to these things but if i was to add many more features i would make it a component
 
Could not connect" is what i got when i clicked to your website... can you put the .fla up please?

Regards,

Martin

Computing Help And Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top