Creating Flex charts and series is easy if you lay them out in MXML. But creating them programmatically can be a little trickier. Here's an issue that's not too difficult to figure out but that I found wasn't documented in any other articles online.
Every chart object holds an array of series objects: LineSeries, AreaSeries, BarSeries, etc. One day I wanted to create a chart that showed columns of data so I wrote what I thought would be a chart with ColumnSeries.
However, I was stumped when no series showed up on my chart. Where did they go?
Turns out, all ColumnSeries have to be included in a ColumnSet, and the same for BarSeries in a BarSet. The *Set objects in turn have another array of all the *Series they hold. So a chart that correctly houses ColumnSeries would look like this:
Although the idea of having an array of series objects within an array called series on a chart seems a little difficult, it actually makes a lot of sense. The *Series are stored within an overall *Set object because they are grouped together and are able to be stacked. Using multiple *Sets on one chart allows these groupings to stay separate and stacked charts to stack correctly without being lumped together.
So the other day I was working with a TabNavigator when I noticed this:
My first tab's label was getting ellipsed! My first thought was that the tab was just too short and needed to be wider. So I made the tabs overly large. Still no luck, now I had a 500px tab that said "In..."
My next thought was that maybe my skin was causing some trouble. After resetting back to the default style I realized that if I moused over the tab with or without skin, the label would show correctly.
It looks as though the TabNavigator occasionally just slips and doesn't validate it's label display. So here's what I did for a quick fix.
This ended up being a pretty simple solution, I just invalidated the size of the tab after it was completely rendered and that took care of the problem. This is a pretty rare occurrence with the TabNavigator but it's a pretty handy fix to have just in case.
From the name it may appear that HtmlUnit is only used for unit testing. While it has extensive logging and error detection, it is really a browser client including Javascript and SSL support that can be used along with a testing framework.
A few uses of HtmlUnit without a testing framework would be to:
monitor information from a web site that doesn't have a web services interface. An example would be an internal build servers status page.
automate logging into a website and posting status reports on a regular schedule.
Here are a few tips to get HtmlUnit set up quickly for use in automation. See documentation on the project page for more info
1. Download htmlunit-2.4.zip off of the project page: http://htmlunit.sourceforge.net/. Or if you are using Maven to build your project, include the following dependency:
Playing sound is a big part of any rich media application and it's very likely you'll need to do it in your future iPhone apps. Before version 2.2 of the SDK this was somewhat difficult -- you needed to either roll your own player or use AudioQueueServices. To use the latter you have to create a bunch of C-style structures and callbacks to feed the data manually byte by byte. It's a very programming intensive process while all you want to do is just load and play a sound!
To remedy this problem Apple introduced a new Framework: AVFoundation and a new audio player: AVAudioPlayer. It has the simplicity you desire but the features you need in order to play your audio files: play, stop, seek, and pause. You can also choose to register a delegate to get certain events like errors in playback, notification when playback ends, and interruption events for when phone calls occur. Pretty cool stuff.
//Make sure you're building for 2.2 and you are also including AVFoundation.framework#import <AVFoundation/AVFoundation.h>
AVAudioPlayer* player;
...
/* Both these actions are hooked up to buttons in IB */-(IBAction)startPlayback:(UIButton *)sender {if(!player){/*
* Here we grab our path to our resource
*/NSString* resourcePath =[[NSBundle mainBundle] resourcePath];
resourcePath =[resourcePath stringByAppendingString:@"/grabbag.m4a"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;
//Initialize our player pointing to the path to our resource
player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){//bail!
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}else{//set our delegate and begin playback
player.delegate = self;
[player play];
}}}-(IBAction)pausePlayback:(UIButton*)sender {
NSLog(@"Player paused at time: %f", player.currentTime);
[player pause];
}
That's all you need to do to play a sound... create a file URL, init, and play! Pausing is done by a simple method call, and you can monitor the location in the song by checking the currentTime property of the object.
Today I needed to load a local html file into a UIWebView and jump to a specific section in the file. I thought this is simple enough all I have to do before creating a NSURL is make sure the url string has the correct anchor appended at the end of it. So I tried:
Unfortunately it turns out that [NSURL fileURLWithPath:stringUrl]; encodes the string converting the # symbol into %23 escape code, which prevents the page from loading. Finally I found the solution by first creating a NSURL variable and then appending the anchor link to it. Here is the code that got the job done: