2013-06-26

Strange Behavior: UIButton Text will be not shown.

Because of a multilingual project, all the texts should be translated and replaced with the correct language version. Everything was fine until I found that a button won't show the text assigned.

The code:


 [button titleLabel].text = @"I won't be changed";


The result is: the button shows always the text that is set up in the storyboard. If I delete the text in Storyboard, it will even disappear when I tap!

The solution is also simple:


[button setTitle:@"I will change" forState:UIControlStateNormal]


via StackOverflow

2013-06-17

One Class for One Problem

The keyboard on iOS devices is sometimes a nightmare for a programmer.  Take the UITextField as an example, when a keyboard appears, it will cover most screen area and let the text fields hidden in the back of the soft keyboard. A solution provided by Apple is using the UIScrollView, but there are a lot of mathematical calculation for a programmer. :(

After a while research on the internet, I've found that Michael Tyson has built a drop-in solution for such kind of problems. He packs everything that one needs into a class and puts the sources on GitHub.

If you follow the instruction on the Github, the task with UITextField and Keyboard is easy as a cake!

Usage

For use with UITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make your UITableView a TPKeyboardAvoidingTableView in the xib. If you're not using a xib with your controller, I know of no easy way to make its UITableView a custom class: The path of least resistance is to create a xib for it.
For non-UITableViewControllers, drop the TPKeyboardAvoidingScrollView.m and TPKeyboardAvoidingScrollView.h source files into your project, pop a UIScrollView into your view controller's xib, set the scroll view's class toTPKeyboardAvoidingScrollView, and put all your controls within that scroll view. You can also create it programmatically, without using a xib - just use the TPKeyboardAvoidingScrollView as your top-level view.


Well done, Michael!

via ATasty Pixel

HOWTO: UIScrollView scroll to bottom programmatically

The autolayout function of a view controller is very useful. The UI elements can find their position after a rotation automatically. Except for UIScollerview...Orz

The reason is: The Layout in Storyboard is normally designed for portrait, not for landscape. So if an user rotates his iOS devices, the UIScrollView cannot resize its content height automatically. So a programmatical resize is needed. BUT, there is another way: just scroll the UIScrollView to the bottom(or where you want), the content will be presented in landscape correctly like in portait.

Here is the solution: Adding the following code to the view controller where the scroll view is.



-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Scroll to the bottom
CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
[self.scrollView setContentOffset:bottomOffset animated:YES];
}

via StackOverflow

2012-08-21

iOS: nested push animation can result in corrupted navigation bar


Today I got a very strange error by running an iOS App:

1. nested push animation can result in corrupted navigation bar
2. Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

It happens when the view controller tries to pop to top view controller without waiting for the loading end of child view controller.

Solution:

1. try to set a boolean variable to mark the view controller should pop to the top view controller
2. in viewDidAppear:(BOOL)animated method, check if a call of [self.navigationController popToRootViewControllerAnimated:YES] is needed

The reason:

popToRootViewControllerAnimated() must be called after the view appears!

2012-08-06

Fixing double entries in "Open with" menu under Mac OS X

Sometimes it is very annoying to see duplicated entries in the "Open with..." menu under MAC OS X, the reason is just the database for file types doesn't refresh for some reason. Now it can be fixed using:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user

Tested under Mac OS X 10.8 (Mountain Lion).

2011-12-22

Fix the cydia crash problem after jailbreak iOS 5 with redsn0w 0.9.9b9

It is really weird. After using redsn0w 0.9.9b9 to jailbreak my iPhone 3GS with iOS 5.0.1, the iphone can be booted with the option "just boot" in redsn0w. The Cydia icon showes up on the screen. Open it and say I am a "User". The loading process can be seen, and... quit. I can ssh into the iOS, that is to say, the iphone is already jailbroken. But what happened with Cydia?!

I've tried many different methods.

1. restore the stock firmware and do the jailbreak again. -> No success.
2. reinstall Cydia with SSH on the iPhone. -> No success.
3. just boot the iphone tetherly again and again -> No success.


So I tried to read the log file of Cydia. The log file can be found at /private/var/tmp/cydia.log. I noticed that an error is repeated again and again.


2011-12-22 14:43:20.135 MobileCydia[252:e07] Setting Language: de_DE
Assertion failed: (dictionary->lockFD != -1), function IDXUserDictionaryOpen, file /SourceCache/Mecabra/Mecabra-248/mecabra/IDXUserDictionary.c, line 88.

I've googled for a while and nothing is found...but it must be something wrong with the laguage settings. I've discoved I use English as user interface language and German as date/time format. Mumm, maybe that is the problem. I've set the both as English. Now, Cydia runs smoothly without any problems.

In a short, that is a bug of Cydia, it depends on the language settings of iOS! Try to set up the language unified, then it doesn't complain again.

2011-11-19

How to install FontForge on Mac OS X Lion

Since I got some old font files before 2007 and I wanna use them, after some inspection, Font Magager told me that the name tables of the fonts are mssing. In order to add them manually, I googled a while to find out FontForge can do the job.

Now comes the problem. FontForge is open source and doesn't provide any compiled binary for Mac OS X ab 10.6. That means, one must complie it before it can be used. So after a little searching again, I found Garrick's guide [How to install fontforge on mac os lion]. Sadly, the process he used doesn't work for me.

He suggests that it can be done easily with the commands:

brew install fontforge
sudo brew link fontforge

The first command returns some fatal errors:

Error: Failed executing: make install
These existing issues may help you:
https://github.com/mxcl/homebrew/issues/7658
https://github.com/mxcl/homebrew/issues/8144
https://github.com/mxcl/homebrew/issues/8491

Then the answers in those issues suggest:

brew install cairo --use-clang

I tried

brew install fontforge

after successful execution of that command. Then it came with:

Error: Failed executing: make
If `brew doctor' does not help diagnose the issue, please report the bug:
https://github.com/mxcl/homebrew/wiki/checklist-before-filing-a-new-issue

According to the message, I ran the command:

brew doctor

The result was:

Unbrewed dylibs were found in /usr/local/lib.

If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
/usr/local/lib/libfaac.0.dylib
/usr/local/lib/libfreetype.6.dylib
/usr/local/lib/libical.0.0.0.dylib
/usr/local/lib/libicalss.0.0.0.dylib
/usr/local/lib/libicalvcal.0.0.0.dylib
/usr/local/lib/libltdl.3.1.0.dylib
/usr/local/lib/libmp3lame.0.dylib
/usr/local/lib/libmp4v2.0.dylib

Unbrewed static libraries were found in /usr/local/lib.

If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
/usr/local/lib/libdevkit.a
/usr/local/lib/libical.a
/usr/local/lib/libicalss.a
/usr/local/lib/libicalvcal.a
/usr/local/lib/libkld.a
/usr/local/lib/libltdl.a
/usr/local/lib/libredo_prebinding.a

Unbrewed .la files were found in /usr/local/lib.

If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .la files:
/usr/local/lib/libical.la
/usr/local/lib/libicalss.la
/usr/local/lib/libicalvcal.la
/usr/local/lib/libltdl.la


So I deleted all the above mentioned files manually and executed the command again.

brew install fontforge


The result:


Error: Failed executing: make
If `brew doctor' does not help diagnose the issue, please report the bug:
https://github.com/mxcl/homebrew/wiki/checklist-before-filing-a-new-issue


Very luckily I saw a warning before the compiling errors, that reads:

Warning: Building with LLVM, but this formula is reported to not work with LLVM:

Compiling cvexportdlg.c fails with error: initializer element is not constant

We are continuing anyway so if the build succeeds, please open a ticket with
the following information: 2336-10.7. So
that we can update the formula accordingly. Thanks!

If it doesn't work you can: brew install --use-gcc


So I tried the command again:

brew install fontforge --use-gcc

Now Mac OS X Lion lets me compile FontForge endly.

In conclusion, the right commands to compile FontForge on Mac OS X Lion should be:

brew install cairo --use-clang

brew install fontforge --use-gcc


In order to see FontForge in Application folder, you need to run this command:

ln -s /usr/local/Cellar/fontforge/20110222/FontForge.app /Applications

2011-11-14

iOS BUG: Synced music won't appear in iPod or Music App

Yesterday I've updated my iPhone 3GS by the means of OTA (Over The Air) to the newest firmware iOS 5.0.1. Everything runs smoothly, BUT! After I open the supplied Music App, I've seen only a very little part of my music collection? Where did they go?



Firstly I thought the update deleted my not-from-itunes-store-bought music files, then I checked the iTunes, the status bar of my iphones indicates that there are exactly 13.6GB music files on it. It appears that the mediathek file on the iphone has corrupted with the update, or maybe the update has changed the structure of the mediathek file and forgetten to update it.

What can I do? Sure, completely restore is one way but also the last way I wanna go. So I've googled around for a while to find out a better and smart way to correct it. Then I found this article [iOS 4.2 bugs: iPhone music gone after the update? Here’s the fix! ]. Okay, i am not the only one and iOs 5.0.1 is also not the only one with that bug.




  1. Grab your cable and plug your iPhone into iTunes on your Windows or Mac PC


  2. When your iPhone shows up in the sidebar, make sure you can see the content listings beneath it (click on the triangle to the left if not)


  3. Click on music


  4. Pick a song


  5. Play it in iTunes


  6. Sync your iPhone


The method in that article didn't work for me for the first time. I have to figure out why it doesn't work. The reason behind that method is: Change the play count for a song, then iTunes changes the mediathek file on the iPhone.

So it is very important for that method, just try to play a song and maybe you can forward it very quickly to the end, make SURE that the play count of that song changed and resync!

Things are gonna be alright and we don't know when apple will fix that long-lasting bug.

2011-11-10

Goodbye, Flash on mobile devices!

Now the war is over. Adobe has declared that they abandon the development of Flash on mobile devices. The winner is HTML 5.

Like Google has mentioned before, the future of Internet belongs to the browser. If we think it further, in the future there should be at least one browser on one device, that means, developers should consider how and what information should be delivered, but not on what kind of devices will support it.

In other word, HTML 5 won this war just because one of its properties, "once programmed, run everywhere". Sounds familiar, right? Sure, it is the slogan of Java.

In my opinion, the device in the future should have some CSS rules to let the end user know what kind of mobile device they use. Take Mobile Safari as an example, its UI elements on a website without CSS are looked exactly like an app on a iPhone.

Now the day is coming, are you ready for the changing?

2011-11-04

Fix the problem with Captive Network under Mac Lion 10.7.2

The Auto Logon Window for Captive Network in Mac OS X Lion is very handy, but with the update 10.7.2 there are so many problems with such a feature happened. Sadly I have to use the IE in my VM Windows to get me logged in.

Now here is the solution:

Use Terminal or Text Editor to edit the file /etc/hosts and add the following lines to the end:

127.0.0.1 crl.usertrust.com
127.0.0.1 ocsp.usertrust.com
127.0.0.1 crl.incommon.org
127.0.0.1 ocsp.incommon.org
127.0.0.1 crl.comodoca.com
127.0.0.1 crl.comodo.net
127.0.0.1 ocsp.comodoca.com

After that, the DNS cache must be cleared with Terminal Command:

dscacheutil -flushcache

Log off and log on, you will see the missing feature again under Lion 10.7.2.


The reason:

With the update 10.7.2 Lion has made some errors on CSL certificates, especially on some captive networks that need the user wait for a few seconds.

Enable AirDrop on older Macs

We all know that Apple has disabled the useful function AirDrop on its older Macs. Now with some work in Terminal, you can enable AirDrop for many older Lion systems at the Terminal command line. Enter:
defaults write com.apple.NetworkBrowser BrowseAllInterfaces 1

After setting the defaults, A restart of Finder will be necessary:

killall Finder

Once you do, you will see the AirDrop icon on the left panel of Finder.

2011-09-16

Review of Adobe Edge Preview


Adobe has shown the newest HTML authorizing tool Adobe Edge for a while. Acoording to Adobe, with that tool the making of animated web pages should be easier. Precisely, "Adobe Edge create animated web content using HTML5, CSS3 and JavaScript with ease, power and precision". With a lot of interest I have tested the product. The version Preview 1 is of Aug. 18, 2011 and the Preview 2 of Sept. 8, 2011.

The experience from Preview 1 is really disappointed. There are only 4(!) tools available on the toolbar: select, rectangle, rounded rectangle and text. So only thing I can do is draging the tools to the stage and making some changes to the object.

Now comes the so called big part. The animation part will be done with a timeline that is very similar to that in Adobe Flash. Define the starting and ending property value, the animation (between frames) will be generated automaticly. After doing that, we can take a preview in a browser directly without saving.

If we look at the source code, Adobe Edge utilites jQuery framework actually to make the animation possible. All the animations are capsuled in one generated JavaScript file and all the propery changes will be defined in one CSS file. The part of the html contains only the UI element.

The source code of a html file looks like that:


<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<!--Adobe Edge Runtime-->
<script type="text/javascript" src="edge_includes/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="edge_includes/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="edge_includes/edge.0.1.2.min.js"></script>
<script type="text/javascript" src="edge_includes/edge.symbol.0.1.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="Untitled-1_edge.js"></script>
<link rel="stylesheet" href="Untitled-1_edge.css"/>
<!--Adobe Edge Runtime End-->

</head><body style="margin:0;padding:0;">
<div id="stage" class="symbol_stage">
</div>
</body>
</html>


That idea sounds good, because the user can use Adobe Edge as Adobe Flash. BUT, wait a second, the real world is very complicated. What about a property that is only deteminated by runtime or even by the related position to other objects? Adobe Edge seems cannot afford such kind of work at the moment.

Actually, Adobe Edge is somehow like Adobe Catalyst compared with Adobe Flash Builder. In Adobe Edge, the source code of a html file cannot be seen or edited. It is really like a tool for traditional Flash developers who begin to jump into the html world.

As fas as I said, there is still a long way for Adobe Edge to go to let the web developers accept the tool.

2011-09-09

Ubuntu (11.04) "Unity" now fails on OSX Lion (10.7) with Parallels (6.0.12094)

It is actually a discussion from
http://forum.parallels.com/showthread.php?t=112331

The story is like this. When I used Ubuntu (11.04) "Unity" on OSX Snow Leopard (10.6) with Parallels (6.0.12094), there was no problem at all. All the graphic effects can be switched on to make my eyes happy. After updating the totally new advanced operating system Mac OSX Lion(10.7), it did not work any more.

I did some research on the net. Then I found out that the issue has been reported to the Parallels company and they promised to fix it. After two months waiting on the patch (normally an update for version 6), now come the news said that the Paralles has a new version of 7. In order to fix the problem, we should take an upgrade for $49! So that is the deal, if we buy the Parallels 6 after 1. August 2011, we can get an upgrade for free. But(!) the issue is reported already right after the opening date of Mac OSX Lion, which is 22. July. So it is unfair for such people who bought the Version 6 after upgrading their mac to Mac OSX Lion.

Anyway, let's see if that fix will be ported to Paralles 6 too since the company assures that the Version 6 should also run on Lion.

Reborn

It seems somehow a long time passed by that I didn't make a new post here. The reason is very simple: the iPhone.
Since I've used the iPhone around 2009, it is always a tough job for me to post something on blogger.

There are many apps on iPhone which can do the communication well, such as twitter, Facebook and so on. But until today Google gets the blogger app on the iPhone. So I think it may be already too late for such service from google. Anyway, I will try to update my blog here from today :-)

2009-10-22

HOWTO: Install Java 1.4 & 1.5 on Snow Leopard

Because of some projects, I need to complie some Java projects in Eclipse with older Java versions, such as 1.4.2, on my MacBook, but since Snow Leopard is such a new(!) operating system, it lacks a lot of support for softwares running with older versions of libraries.

After a long while searching in the internet, finally I found the way to install JVM 1.4 & 1.5 on Snow Leopard!

Java 1.4:
Here is how to get Java 1.4 running on snow leopard.
cd /tmp/
curl -o java.1.4.2-leopard.tar.gz http://tedwise.com/files/java.1.4.2-leopard.tar.gz
tar -xvzf java.1.4.2-leopard.tar.gz
sudo mv 1.4.2 /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo ln -s 1.4.2 1.4
open "/Applications/Utilities/Java Preferences.app"
and Java 1.5:
cd /tmp/
curl -o java.1.5.0-leopard.tar.gz http://tedwise.com/files/java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz
sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leo
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo mv 1.5.0-leo 1.5.0
sudo ln -s 1.5.0 1.5
open "/Applications/Utilities/Java Preferences.app"
It really works! ;-)

via [OneSwarm]

Update (2014-05-05): the broken links are fixed.

2009-09-29

Some Reasons Why I Don't Update My iPhone (1st Gen) To Firmware 3.1

The firmware 3.1 for iPhone has been released for a while. Every time when I plug in my iPhone to my Macbook, the iTunes reminds me always of a new iPhone OS available. But I must say no to iTunes every time. So why I don't want update my iPhone to that version 3.1? There are 5 reasons or at least my considerations.

PROs:
1. PwnageTool 3.1 (http://blog.iphone-dev.org/) is ready for the go. AppSync for OS 3.1 in Cydia is appeared too. (Instructions)
2. iPhone OS 3.1 has the funtion that man can arrange the application layout directly in iTunes.
3. Genius Mix will be supported.

CONs:
1. For non-Standard accessories there are still no hacks appeared like 3.01. The magic is called iapd. It fixs the problem with the message "This Accessory is not made to work with iPhone"

2. It's possible to develope iPhone applications for jailbroken iPhone 3.0 with a patched XCode 3.1.3. (Source) But until now, I didn't get how to make it work with iPhone OS 3.1 and XCode 3.2.


Updates!
1. MichaelS confirmed that the pathed iapd for 3.0 also works for 3.1.2!
2. Xcode 3.2 works
with jailbroken iPhone 3.1 too according to
the "Float Middle" Blog.


So, now it is the time to update! :)

2009-07-22

Passing Additional Parameters Or Arguments Using addEventListener In Flex

With Adobe Flex one can make a lot of things. In the heart of its event-driven-programming, there is a famous function called addEventListener(). From Adobe LiveDoc we can see the syntax is like:

addEventListener() method
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void

Parameters


type:String — The type of event.


listener:Function — The listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this example shows:
function(evt:Event):void

The function can have any name.



useCapture:Boolean (default = false) — Determines whether the listener works in the capture phase or the target and bubbling phases. If useCapture is set to true, the listener processes the event only during the capture phase and not in the target or bubbling phase. If useCapture is false, the listener processes the event only during the target or bubbling phase. To listen for the event in all three phases, call addEventListener twice, once with useCapture set to true, then again with useCapture set to false.


priority:int (default = 0) — The priority level of the event listener. The priority is designated by a signed 32-bit integer. The higher the number, the higher the priority. All listeners with priority n are processed before listeners of priority n-1. If two or more listeners share the same priority, they are processed in the order in which they were added. The default priority is 0.


useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.

Class-level member functions are not subject to garbage collection, so you can set useWeakReference to true for class-level member functions without subjecting them to garbage collection. If you set useWeakReference to true for a listener that is a nested inner function, the function will be garbage-collected and no longer persistent. If you create references to the inner function (save it in another variable) then it is not garbage-collected and stays persistent.


Throws

ArgumentError — The listener specified is not a function.

See also


========================================================
There is no way to pass some addtional parameters to an event handling function!

Deva Raj's solution is fine, but without some explaination it is hard to understand.

So the quick and dirty way is to use an inline function:

btn1.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){myEventHandler(e, btn1.id)});

public function myEventHandler(e:MouseEvent, btnId:String) {
Alert.show("Clicked button"+btnId, "Great Title",Alert.OK);
}

Here btn1.id is just an example parameter, you can replace it with what you want.

Another better(!) solution is to create custom Event, which you can find it here:

ActionScript Code:
package com
{
import flash.events.Event;

public class EventWithData extends Event
{
public var data:*;

public function EventWithData(type:String, data:*,
bubbles:Boolean = false, cancelable:Boolean = false)
{
this.data=data;
super(type, bubbles, cancelable);
}

}
}
The mechanism details can be found also in Adobe LiveDocs: Registering event handlers

2009-06-18

How to write a Java-based HTML-Crawler?

It's actually a task from my test work. First idea that came to me is: Use an instance of XMLReader to fetch a page, then use regular expression to parse, save the results with the help of XMLWriter. Such a way seems naive, but almost non-usable! So let me explain the difficulty which can be confronted.


1. Internet is a mess.



There are too many web pages in the cyberspace that do NOT pay any attention to the web standard (X)HTML. So we can see a lot of nested tags, unpaired tags and even worse, badly programmed JavaScript may be in just one page.



2. Ads are confusing.


Now come Advertisements with different formats, e.g. Text, Flash, Images and Videos(!). Most of them live with a lot of JavaScript to improve their impact. Some use even non-standard tags such as <noscript> or browser-specific tags.


3. Ajax is not so user-friendly.

We all love to use Ajax technology. A typical Ajax use case is to let some texts loaded dynamically, then it results a severe problem with a HTML-Parser. If the parser saves the fetched HTML-page in a cache, the cache file contains a lot of JavaScript which load elements later. So with the cache file we cannot get what we want normally.


What can we do with all those?


The current popular solution is to use the HTML or Webpage validation tools! Between different libraries HTMLUnit will fit our requirement exactly. The project describes itself as a "GUI-Less browser for Java programs". So we can handle a webpage just like we see it in our browser. The above disadvantages could be then avoided.


Interesting is, HTMLUnit is originally a java unit testing framework for testing web based applications. It is similar in concept to HTTPUnit but is very different in implementation.


For beginners, HTMLUnit provides a very simple documentation to "Get Started". With the examples provided on the website it's okay to write a HTML-Crawler now.


2009-05-05

blue-chip company

Today I got an offer from a headhunter for a contract-based work. Interesting is, I met a foreign word called "Blue Chip Company". So I did a little research to find out what it really means. Here it is! ;)

1. finance definition:

A company that is very strong financially, with a solid track record of producing earnings and only a moderate amount of debt. A blue-chip company also has a strong name in its industry with dominant products or services. Typically, blue-chip companies are large corporations that have been in business for many years and are considered to be very stable. However, there is no formal requirement for being a blue chip. Often, blue-chip companies are found in the Dow Jones Industrial Average.

2. Better explanation

Blue chip (stock market)

A blue chip stock is the stock of a well-established company having stable earnings and no extensive liabilities. The term derives from casinos, where blue chips stand for counters of the highest value. Most blue chip stocks pay regular dividends, even when business is faring worse than usual.

The phrase was coined by Oliver Gingold of Dow Jones sometime in 1923 or 1924. Company folklore recounts that the term apparently got its start when Gingold was standing by the stock ticker at the brokerage firm that later became Merrill Lynch. Noticing several trades at USD$200 or USD$250 a share or more, he said to Lucien Hooper of W.E. Hutton & Co. that he intended to return to the office to “write about these blue chip stocks.” Thus the phrase was born. It has been in use ever since, originally in reference to high-priced stocks, more commonly used today to refer to high-quality stocks. In contemporary media, Blue Chips and their daily performances are frequently mentioned alongside other economic averages like the Dow Jones Industrial Average.

/////////////////////

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!