Showing posts with label flash. Show all posts
Showing posts with label flash. Show all posts

2009-02-13

The notorious Problem with letterSpacing in Flash

These days I met a problem in Flash with the property letterSpacing of a dynamic text field.

If we are looking at the examples provided by Adobe:

this.createTextField("mytext", this.getNextHighestDepth(), 10, 10, 200, 100);
mytext.multiline = true;
mytext.wordWrap = true;
mytext.border = true;

var format1:TextFormat = new TextFormat();
format1.letterSpacing = -1;

var format2:TextFormat = new TextFormat();
format2.letterSpacing = 10;

mytext.text = "Eat at \nJOE'S.";
mytext.setTextFormat(0, 7, format1);
mytext.setTextFormat(8, 12, format2);

The problem is, this doesn't work for a dynamic text field, only for dynamic generated text field!

There are a lot of solutions on the internet.

Solution 1:

var
styling:TextFormat = new TextFormat();
styling.font = "Blackadder";
styling.color = 0xBA1424;
styling.letterSpacing = 15;

tf.setNewTextFormat(styling);
tf.text="mööööp"


This one doesn't use the method setTextFormat() to set the letterSpacing, instead of that, setNewTextFormat() will be used.

Solution 2:

From the blog "Summit Projects":

function setTextFormatting(){
var fmt:TextFormat = club_name.name.getTextFormat();
club_name.name.setTextFormat(fmt);
club_name.name.setNewTextFormat(fmt);
club_name.name.autoSize = “left”;
}


He said, "It’s silly, but it works.". Unfortunately, it didn't work in my case.

Solution 3:

Bob Walton suggests that in his blog "Flash: yourMom.getTextFormat(); //is the key to letterSpacing"

var fmt:TextFormat = myTextField.getTextFormat();
myTextField.setTextFormat(fmt);
myTextField.setNewTextFormat(fmt);


This also didn't work for me.

I spent hours to figure out how can I fix it. Now here is the solution from mine.

txtCtrl.html = true;
txtCtrl.htmlText = "<font letterspacing='-3'>Now it is the right one!</font>";


So you can see, I got no sucess on setting the format of a dynamic text field. At the end, a font property can achieve that so easily!

2007-07-16

Problems with IMG html tag in Flash 8

In these days I am fighting with some bugs in Flash 8. So comes the problem: I want to create a text field in Flash 8, and change its properties to "dynamic text" with "multi-line", "selectable" and "render as HTML", then I connect the text field to some html contents. Everything is fine, until I try to show some pictures using the html tag img. The result: NO imgs are shown.

After long long time with try-error and searching in the net, finally I found the reason for such problems. There are some bugs with IMG html tag in Flash 8. My solution is: After the img tag, insert at least 8 <br /> tags.

To be careful: The support of img tag is only available from Flash v7 and ActionScript 2.0. So please pay attention to your publish settings too.

2007-05-15

Best tutorials on Sending Email from Flash using PHP

I've tried a lot of tutorials on the web, in order to make a working contact form in flash. Endly I found one: Sending Email from Flash using PHP

The best part of that tutorial is: it points out tons of tips which could drive man crazy without. For example, you'd better hide the send button in a Movie Clip, so that everything works. Why? because otherweise

Note: note that [ send ] is a Movie Clip with inside a button. This is useful for us while with the loadVariables() our vars to PHP without sending all _root variables...
Reading such kind of tutorials is really an enjoy. Keep going on, Alessandro Crugnola!

2007-05-14

Using the UIScrollBar component of Flash

In a recent project I tried to use the UIScrollBar component of Flash 8. There are already a lot of tutorials on the web:
  1. Creating a Flash Textbox Input
  2. Creating a Text Scroller
If you do that step by step, it works. BUT, if you create a new text box with the type of dynamic text, use LoadVars to load a text file on the fly and add a UIScrollBar component to it, then publish it, you will see a blank vertical bar on the right of the text box. So what's wrong?

There are also people writing comments on the Adobe livedocs. Such things cost me at least one hour to find what happens.

The key to the solution is: you must enter something long enough in the text box before loading anything into it! I guess the UIScrollBar component just caculates the behavior before it's published. The only size it knows is your text size in the design phase.

So, don't forget to paste some dummy text in your text box and give it an instance name before you use the UIScrollBar component!

2007-05-03

Sending Email in Flash

Contact form is used widely on a website. If the website is powered by Flash, find a better way to build a flexible contact form is also very important.

There are probably 3 ways:

1. Use the "mailto:" protocol

Namely set a button event with

on (release) {
getURL("mailto:" + to + "?subject=" +subject+ "&body=" + body);
}
The three variables are self defined in Flash according to the form fields.  A tutorial can be found here.

The advantage of this method is that man doesn't need complex programming things. The flash will call the email client in the system to send the mail.

The shortcoming is also related to the advantage: If an email client isn't setup well or doesn't exist on the system, then we have a problem.

2. Use FLASH and PHP

It's used widely. So I don't want to talk more abut it. ;-) 

The principle is: Flash posts Variables to a PHP file, then the PHP sends email using mail() function and returns the result to flash.



A tutorial can be found at kirupa.com

3. Load a HTML into FLASH

The principle here is trying to load a html with contact form in Flash.

Firstly just use a textfield in Flash, set it to dynamic. Then click Render Text as HTML in properties or set the .html property to true. Then use Loadvars to load the html file and assign the variable into the textfield.htmlText property. Here's an example:
loadText = new LoadVars();
loadText.onLoad = function()
{
_root.helpText_txt.html = true;
_root.helpText_txt.htmlText = this.testText;
}
loadText.load("text.htm");
Just remember the following: You don't need all that header junk like tags and such. At the beginning of your html file, above everything else put something like:

testText =

where testText can be any variable name you choose. You can only use jpg and swf's for graphics embedded in the html. And the jpg's can't be progressive jpg's.

Finally anchors "<a href="http://www2.blogger.com/bla.html">" will work but won't show as a different color unless you use font tags around them and specify to change the color of the text. ie. "<span></a><a href="http://www.blogger.com/bla.html">Bla</a></span>"

More infos about "Formatting text with Cascading Style Sheets" can be found here.

P.S. According to this article, there are many ways to link a html in Flash.