PDA

View Full Version : How can I make these Buttons?



Daimz
September 8th, 2006, 10:07 AM
I have made a content managment system and I am using basic input text boxes to input text into my database and allowed html to be read in the reading part of the CMS. So what I am wanting to know how to do is create a button that would insert say a bold tag into my input box. so that when the user is doing an update and wants to make a specific section bold or add a picture he could click on a button like <img src> and that would insert <img src=""> something like that or <b></b> just makes it a bit easier. How would I be able to acheive something like this using buttons?

flashpipe
September 8th, 2006, 10:34 AM
Here's a bit of code I'm using on my Bold button which toggles the format of selected text in an input field named 'inTxt'


on (release)
{
Selection.setFocus(this.inTxt);
Selection.setSelection(this.SelBegin, this.SelEnd);

var f:TextFormat = new TextFormat();

f = this.inTxt.getTextFormat(this.SelBegin,this.SelEnd );
f.bold = !f.bold;
this.inTxt.setTextFormat(this.SelBegin,this.SelEnd ,f);
}

and here's the frame text which gets Selection:


this.onEnterFrame = function()
{
var s:String = Selection.getFocus();

if (s == null)
{
return;
}

if (Selection.getFocus().indexOf("inTxt") >= 0)
{
SelBegin = Selection.getBeginIndex();
SelEnd = Selection.getEndIndex();
Cursor = Selection.getCaretIndex();
}
}

.fla attached...

Hope that helps!!

Daimz
September 8th, 2006, 09:03 PM
Sweet thanx alot man that helped heeps I manage to make and italic, underline and bold button so thanx a heep.
I have a few more queastions tho:
How can I make a Url button that will create links?
How can I make a font color button?
And lastly how can I make an insert image button?

would really appriciate any help with any of those queastions.
once again thanx for the help it works perfectly:thumb:

ThePuzzleMaster
September 9th, 2006, 08:41 AM
You just need to look up the textFormat in the flash help file. if you can change the italic and underline and whatnot, it also has a similar property .font that will change the font.

For urls, you simply need to assign getURL(input_txt,_blank) to the button.

For the insert image button, what exactly do you want to happen. Not sure if I understand that one.

Daimz
September 9th, 2006, 10:22 AM
ok well I just done another test to make sure the buttons I made are working. however there is a slight problem they work fine in the input section but the bold/italic/undeline information is not being stored in the database so when I the data comes back and is being read it is no longer bold or italic. does anyone know how i can fix this? here is what I have got so far just to give you a better idea of what I mean:
http://www.arctosdesign.com/writting.html
I think I need to actually be writting the html like <b></b> to the database. would it be possible to make the buttons generate the html so take the bold button it shows up as bold and works perfectly fine but it stored at html in the databaes.(if that makes sence)
in the example I have shown I am actually using the FTElight component.....dono if that helps.

ThePuzzleMaster
September 10th, 2006, 07:08 PM
Well, one thing you could do would be to make it add an <b> when you press the bold button, and then add a </b> the next time yo upressed it. That would be one solution...

Another would be to run the text through a checker function at the end once update is pressed. Just a function that checks the textFormat settings and for instance,


if( textFormat.bold==true){
input_txt.text="<b>"+input_txt.text+"</b">
}


You'd have to figure out a way to have it only check the individual parts though, since the bold button effects only sections of the text and not the whole thing. I think the first option would be best... And easiest.

Daimz
September 10th, 2006, 07:43 PM
I think the first option sounds like the best idea. However I dont quite understand how I would set a button up like that(still really new to actionscript). Would you be able to explain a bit more indepth for me please?

ThePuzzleMaster
September 10th, 2006, 08:29 PM
Well you have your text input box with a variable input_txt (Or whatever you call it...) Then you just code your button so that in addition to changing the textFormat style it also:


bold_btn.onPress=function(){
if(bold=="true"){///checks to see if button is already activated//
format.bold=false;///sets the textFormat.bold to false///
input_txt.text=input_txt.text+"</b>"//changes teh textbox to //contain it's current text plus "</b>" at the end
bold=="false"//changes bold to inactive//
}else if(bold=="false"{
format.bold=true;///sets the textFormat.bold to true///
input_txt.text=input_txt.text+"<b>"//changes teh textbox to //contain it's current text plus "<b>" at the end (which is where new text will //appear)
bold=="false"//changes bold to inactive//
}
}


I think that should work. I'm not super familiar with input text, but I believe that should work. Also, put in your current code that copies the text over to the databse of course.

Daimz
September 10th, 2006, 09:31 PM
Also, put in your current code that copies the text over to the databse of course.
what exactly do you mean?

Daimz
September 10th, 2006, 09:45 PM
lol sorry to be a pain I just tried the code you gave me and I cant seem to get it to work I think i might be laying it out worng or maybe I just havent quite understood how to put it together because when I run the fla and add text and try make some bold nothing happens?