Thursday, November 17, 2011
Flash Builder not auto completing
I imported an existing project into FlashBuilder 4.0 and found that content assist (and class linking) didn't work. After a bit of googling and testing it turns out that when you import a project the compiler looks for the main classes in the src folder. If you have them in a different place you need to explictly set this by right clicking the project > properties > Actionscript Build Path and then set the "Main Source folder" to the custom location (it will be set to src by default).
Saturday, July 2, 2011
Setting up the mic for Mac Book
My sister in law and a friend were having trouble setting up the single audio input on the Mac Book to record some audio and couldn't figure out how to get the Mac to use it as an input jack instead of the speaker output. So for anyone else having the same problem, here are the directions:
Open the System Preferences panel -- the icon looks like this:
Then in the Hardware section click on Sound (last icon on the right):

On this next screen choose the last option item "Input" (on the far right):

Then at the bottom of this screen select the dropdown for "Use audio port for" and select "Sound Input":

Your line in should now work....
Of course, once you're done you'll have to reset this to "Sound Output" again so that you can use speakers or headphones :-)
Open the System Preferences panel -- the icon looks like this:
Then in the Hardware section click on Sound (last icon on the right):
On this next screen choose the last option item "Input" (on the far right):

Then at the bottom of this screen select the dropdown for "Use audio port for" and select "Sound Input":

Your line in should now work....
Of course, once you're done you'll have to reset this to "Sound Output" again so that you can use speakers or headphones :-)
Wednesday, April 20, 2011
missing images in iPhone using Titanium
Note to future self: If you build an app in Titanium -- do NOT create a folder in the images directory called 'iphone' to place iphone specific images there. They will show up in the emulator but not on the device. I ran into this a few months ago but didn't document the solution and just spent another 2 hours trying to debug it a separate time. Use any other name than 'iphone'!!!
Wednesday, April 13, 2011
Titanium createHTTPClient issue on Android
Setting up an Android app on Titanium, I was having problems getting a webservice using a signature. It was working fine on iPhone. Turns out that Titanium auto url encodes the url in an createHTTPClient.open() method -- thus sending a different string than the signature had hecked against -- and thus returning an error.
To fix it, do this:
var xhr = Titanium.Network.createHTTPClient();
xhr.autoEncodeUrl = false;
before you call the open() method.
To fix it, do this:
var xhr = Titanium.Network.createHTTPClient();
xhr.autoEncodeUrl = false;
before you call the open() method.
Saturday, February 19, 2011
Blackberry Playbook error using AIR StageWebView
Here was a crazy error on the latest Blackberry Playbook simulator (0.9.3). If you reference a non-existent file or image, it throws this error:
Error #2044: Unhandled ErrorEvent:. text=Couldn't read a file:// file
It was no fun trying to figure out where this bug was coming from! :-(
Error #2044: Unhandled ErrorEvent:. text=Couldn't read a file:// file
It was no fun trying to figure out where this bug was coming from! :-(
Thursday, February 3, 2011
Facebook Places throws oAuth error: "The table you requested does not exist"
Just did a great workshop with Conrad Fuhrman who demonstrated his ARTi application, an augmented reality app build with Titanium. It also uses a new Titanium Facebook module that allows you to connect to Facebook using oAuth. However, when I tried to run the code sample I kept getting this oAuth error:
entries =>
{contents = "type"} = {contents = "OAuthException"}
{contents = "message"} = {contents = "(#603) The table you requested does not exist"}
}
}
After a google search this post turned up which explained it all. It turns out that Facebook Places does not work outside of the US, and since I was trying to access it from Barbados, it was failing.
entries =>
}
}
After a google search this post turned up which explained it all. It turns out that Facebook Places does not work outside of the US, and since I was trying to access it from Barbados, it was failing.
Friday, January 14, 2011
Detecting Android and iPhone using Javascript
Here is how you can detect iPhone/ipod and android using javascript:
http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
Monday, January 10, 2011
Creating scrollable divs on a Mobile device
On mobile devices the scroll property cannot be set for divs on the page since the page itself is scrollable. Google has released a possible workaround that I am trying to get working. It involves disabling the scroll property of the document and animating the div in response to touch events:
http://code.google.com/mobile/articles/webapp_fixed_ui.html
Update: I just found the YUI Scrollview and (after figuring out a critical step to get the scrollbars to work) its awesome!
http://developer.yahoo.com/yui/3/scrollview/
The problem I ran into was how to get the scrollbars to show up. It turns out that the documentation does not include the need to attach a "yui-skin-sam" style to the container that holds the scrollable div. So in order to make it work here is a very simple example:
http://pastie.org/1454114
http://code.google.com/mobile/articles/webapp_fixed_ui.html
Update: I just found the YUI Scrollview and (after figuring out a critical step to get the scrollbars to work) its awesome!
http://developer.yahoo.com/yui/3/scrollview/
The problem I ran into was how to get the scrollbars to show up. It turns out that the documentation does not include the need to attach a "yui-skin-sam" style to the container that holds the scrollable div. So in order to make it work here is a very simple example:
http://pastie.org/1454114
Friday, January 7, 2011
Getting local HTML file to load in the Blackberry Playbook
I've been trying out the SDK for the Blackberry Playbook and one thing that was stumping me was how to load a local HTML file using the StageWebView in AIR 2.5.
I placed the local HTML file in the root folder (in the same folder as the .mxml file) and tried to load it this way:
**************
import flash.media.StageWebView;
private var webView:StageWebView = null;
private function init():void{
// get the file location
var f:File = new File("app:/map-simple.html");
webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.loadURL( f.url );
}
**************
...but it didn't work. Fortunately, I stumbled on this post by Mike Chambers that explains a workaround and recoded the app this way:
**************
import flash.media.StageWebView;
private var webView:StageWebView = null;
private function init():void{
var fPath:String = new File(new File("app:/map-simple.html").nativePath).url;
webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.loadURL( f.url );
}
***************
This works great!
By the way, I also tried to use the QNXStageWebView in the latest Blackberry SDK but the FlashBuilder (Burrito) compiler gave me the following error:
A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package.
This apparently has been faced by other developers (see here) using the QNXStageWebView and the Blackberry support boards indicate that this is a beta Class and has numerous issues -- so I decided not to try to find a workaround (which seems to involve digging up an older swc file).
One caution, the AIR StageWebView is also still in beta and does not currently allow for communicating between the base app and the StageWebView object. In my case however, I am just trying to get a fully working HTML app to run on the Playbook.
I placed the local HTML file in the root folder (in the same folder as the .mxml file) and tried to load it this way:
**************
import flash.media.StageWebView;
private var webView:StageWebView = null;
private function init():void{
// get the file location
var f:File = new File("app:/map-simple.html");
webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.loadURL( f.url );
}
**************
...but it didn't work. Fortunately, I stumbled on this post by Mike Chambers that explains a workaround and recoded the app this way:
**************
import flash.media.StageWebView;
private var webView:StageWebView = null;
private function init():void{
var fPath:String = new File(new File("app:/map-simple.html").nativePath).url;
webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );
webView.loadURL( f.url );
}
***************
This works great!
By the way, I also tried to use the QNXStageWebView in the latest Blackberry SDK but the FlashBuilder (Burrito) compiler gave me the following error:
A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package.
This apparently has been faced by other developers (see here) using the QNXStageWebView and the Blackberry support boards indicate that this is a beta Class and has numerous issues -- so I decided not to try to find a workaround (which seems to involve digging up an older swc file).
One caution, the AIR StageWebView is also still in beta and does not currently allow for communicating between the base app and the StageWebView object. In my case however, I am just trying to get a fully working HTML app to run on the Playbook.
Thursday, November 11, 2010
Convert string with carriage returns to one line in php
I have a database string containing new lines characters (\n) and needed to print it out with no linebreaks -- since it was being printed as a javascript variable. This script does the trick:
$input = trim( preg_replace( '/\s+/', ' ', $input ) );
courtesy: http://www.codingforums.com/showthread.php?t=137009
$input = trim( preg_replace( '/\s+/', ' ', $input ) );
courtesy: http://www.codingforums.com/showthread.php?t=137009
Sunday, November 7, 2010
Print booklets on Mac
One feature that is missing on Mac Snow Leopard is the ability to print a booklet from a pdf. But here is a great free application that fills that void:
http://bit.ly/2JupkE
By the way, to print even and odd pages on a Mac you need to select the "Paper Handling" option in the "Preview" dropdown.
http://bit.ly/2JupkE
By the way, to print even and odd pages on a Mac you need to select the "Paper Handling" option in the "Preview" dropdown.
Thursday, November 4, 2010
Create AIR app without a taskbar icon
I needed to create a chromeless AIR app that would act like the the old Active Desktop in Windows -- and did not show a taskbar icon that a user could close. Here is how it was done:
Create a new AIR app (for which a taskbar icon is required). This app spawns a new application component based on mx:Window with the HTMLLoader in it. I used a separate component for this so it could function independently from the main app. Child apps in AIR do *not* require an icon so you can set the type=NativeWindowType.LIGHTWEIGHT on this new component when you open it. As soon as this new window opens it dispatches a complete event. The main window listens for the complete event and then closes itself -- taking the taskbar icon with it. Since (I believe) in Windows 7 the shortcut "Windows/M" works from the items in the task bar, the fact that the child app is not in the task bar prevents it from being minimized by the shortcut.
By the way, this seems to work only on Windows -- not Mac -- so a different solution would be required for that.
Create a new AIR app (for which a taskbar icon is required). This app spawns a new application component based on mx:Window with the HTMLLoader in it. I used a separate component for this so it could function independently from the main app. Child apps in AIR do *not* require an icon so you can set the type=NativeWindowType.LIGHTWEIGHT on this new component when you open it. As soon as this new window opens it dispatches a complete event. The main window listens for the complete event and then closes itself -- taking the taskbar icon with it. Since (I believe) in Windows 7 the shortcut "Windows/M" works from the items in the task bar, the fact that the child app is not in the task bar prevents it from being minimized by the shortcut.
By the way, this seems to work only on Windows -- not Mac -- so a different solution would be required for that.
Thursday, October 28, 2010
Communicating between Javascript and Actionscript in an AIR application
Using the HTMLLoader class you can communicate between javascript and actionscript in the same application. This means that you can trigger AS3 functions from a loaded HTML page through javascript (and vice versa). Here is a quick sample:
// AS3 code:
var windowBounds:Rectangle = new Rectangle(0,0,1024,768);
var htmlLoader:HTMLLoader = HTMLLoader.createRootWindow(true, null, false, windowBounds );
htmlLoader.runtimeApplicationDomain = ApplicationDomain.currentDomain;
htmlLoader.load(new URLRequest('myfile.html'));
htmlLoader.addEventListener(Event.COMPLETE, onComplete);
private function onComplete(e:Event):void{
// creates a new javascript function in the HTML page that map to the AS3 function
// you don't need to define these functions at all in the JS -- they become available automatically
htmlLoader.window.jsFunction = flashFunction;
}
private function flashFunction(msg:String):void{
trace("message: " + msg);
}
Once the onComplete() function runs, it creates the link between the newly created HTML javascript function and the AS3 function -- which can then be called directly in the HTML:
HTML code:
onclick="jsFunction('called from js');"
// AS3 code:
var windowBounds:Rectangle = new Rectangle(0,0,1024,768);
var htmlLoader:HTMLLoader = HTMLLoader.createRootWindow(true, null, false, windowBounds );
htmlLoader.runtimeApplicationDomain = ApplicationDomain.currentDomain;
htmlLoader.load(new URLRequest('myfile.html'));
htmlLoader.addEventListener(Event.COMPLETE, onComplete);
private function onComplete(e:Event):void{
// creates a new javascript function in the HTML page that map to the AS3 function
// you don't need to define these functions at all in the JS -- they become available automatically
htmlLoader.window.jsFunction = flashFunction;
}
private function flashFunction(msg:String):void{
trace("message: " + msg);
}
Once the onComplete() function runs, it creates the link between the newly created HTML javascript function and the AS3 function -- which can then be called directly in the HTML:
HTML code:
onclick="jsFunction('called from js');"
Wednesday, October 27, 2010
Round time to nearest 30 seconds
I had a requirement to round the time for a video (in seconds) to the nearest 30 seconds. Not being so strong in math, I am grateful to be better at Googling. So here it is for anyone else in a similar situation:
Math.round(myTime/30)*30
Awesome and simple!
Math.round(myTime/30)*30
Awesome and simple!
Wednesday, October 20, 2010
Titanium gradient for buttonbar
Doesn't seem that the gradient works for the buttonbar either. So here is the workaround:
myButtonBar = Ti.UI.createButtonBar({
id:'buttonbar',
height:40,
backgroundColor:'#663399',
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
labels:['Close Keyboard >']
});
Just use a background color and the Titanium.UI.iPhone.SystemButtonStyle.BAR as the style -- and the app will create a gradient for you -- from lighter to darker.
myButtonBar = Ti.UI.createButtonBar({
id:'buttonbar',
height:40,
backgroundColor:'#663399',
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
labels:['Close Keyboard >']
});
Just use a background color and the Titanium.UI.iPhone.SystemButtonStyle.BAR as the style -- and the app will create a gradient for you -- from lighter to darker.
Tuesday, October 19, 2010
Show and hide hidden files on a Mac
This command shows the hidden files in Finder on a Mac:
$ defaults write com.apple.finder AppleShowAllFiles TRUE
$ killall Finder
and this hides them again:
$ defaults write com.apple.finder AppleShowAllFiles FALSE
$ killall Finder
$ defaults write com.apple.finder AppleShowAllFiles TRUE
$ killall Finder
and this hides them again:
$ defaults write com.apple.finder AppleShowAllFiles FALSE
$ killall Finder
Friday, October 8, 2010
Titanium does not currently support the clipboard
Just a heads up for anyone that might stumble on this accidentally. Titanium Mobile does not currently support copying to the clipboard. I should have checked that before I coded a copy feature into my app...
Thursday, October 7, 2010
Time Machine issues when hard drive is partitioned
I have a Mac Book Pro (Snow Leopard) and set up Time Machine using a 1 TB Seagate external USB hard drive. The first time I set it up, I partitioned the drive into 600GB and 400GB and used the 600GB partition for Time Machine -- leaving the 400 GB partition for standard backups. However I found that the behavior of Time Machine was very buggy. For instance, if I tried to enter TM with any programs open, the Mac would freeze and I would have to restart.
So in order to use TM I had to close every program I had running. Secondly, about a month ago I maxed out the 600GB and TM stopped working altogether. It would just fail when I tried to back up.
In any event, I reformatted the drive to a single 1TB partition and now Time Machine works exactly as advertised...
UPDATE (November 5): After a few months I have had another error that the HD cannot be used by Time Machine and cannot be repaired. Either the HD is defective for Time Machine just doesn't play nice with it...
So in order to use TM I had to close every program I had running. Secondly, about a month ago I maxed out the 600GB and TM stopped working altogether. It would just fail when I tried to back up.
In any event, I reformatted the drive to a single 1TB partition and now Time Machine works exactly as advertised...
UPDATE (November 5): After a few months I have had another error that the HD cannot be used by Time Machine and cannot be repaired. Either the HD is defective for Time Machine just doesn't play nice with it...
Creating a Titanium gradient button for iPhone
This took a while to figure out. I wanted to get a gradient button in Titanium but there were a number of variables that didn't seem to work properly. Here is a finished button with a gradient from black to lighter gray:
closeButton = Titanium.UI.createButton({
title:'Close',
width:150,
height:40,
style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN,
borderRadius:10,
font:{fontSize:16,fontFamily:_fontFamily,fontWeight:'bold'},
backgroundGradient:{type:'linear',
colors:['#000001','#666666'],
startPoint:{x:0,y:0},
endPoint:{x:2,y:50},
backFillStart:false},
borderWidth:1,
borderColor:'#666'
});
It seems that a few items are critical to make it work:
1. You have to define the style as "style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN" -- BORDERED will not work and if you don't have a style it also won't show.
2. Make sure that the gradient property for backFillStart is false.
3. There seems to be a bug when you put in #000000 as one of the colors. You need to set it to #000001 (or something like that), in order to get black to show
closeButton = Titanium.UI.createButton({
title:'Close',
width:150,
height:40,
style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN,
borderRadius:10,
font:{fontSize:16,fontFamily:_fontFamily,fontWeight:'bold'},
backgroundGradient:{type:'linear',
colors:['#000001','#666666'],
startPoint:{x:0,y:0},
endPoint:{x:2,y:50},
backFillStart:false},
borderWidth:1,
borderColor:'#666'
});
It seems that a few items are critical to make it work:
1. You have to define the style as "style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN" -- BORDERED will not work and if you don't have a style it also won't show.
2. Make sure that the gradient property for backFillStart is false.
3. There seems to be a bug when you put in #000000 as one of the colors. You need to set it to #000001 (or something like that), in order to get black to show
Sunday, September 26, 2010
Titanium Titanium.App.Properties problem
Here is another case where in Titanium the iPhone simulator successfully runs a feature that fails on the iPhone. In this case its the Titanium.App.Properties. This is supposed you allow you save global variables. From the documentation, you set it up like this:
Save variable:
Titanium.App.Properties.setString("myVar","myValue");
Retrieve variable:
Titanium.App.Properties.getString("myVar"); '// returns "myValue"
This works fine on the simulator but fails on the iPhone unless you follow two additional steps:
1. From the Kitchen Sink project -- copy /modules/iphone/settings.bundle
2. Create a /modules/iphone folder in your project and paste the settings.bundle file there
3. Make sure to name all your variables with a "_preference" suffix. So our examples above should be:
Save variable:
Titanium.App.Properties.setString("myVar_preference","myValue");
Retrieve variable:
Titanium.App.Properties.getString("myVar_preference"); '// returns "myValue"
Save variable:
Titanium.App.Properties.setString("myVar","myValue");
Retrieve variable:
Titanium.App.Properties.getString("myVar"); '// returns "myValue"
This works fine on the simulator but fails on the iPhone unless you follow two additional steps:
1. From the Kitchen Sink project -- copy /modules/iphone/settings.bundle
2. Create a /modules/iphone folder in your project and paste the settings.bundle file there
3. Make sure to name all your variables with a "_preference" suffix. So our examples above should be:
Save variable:
Titanium.App.Properties.setString("myVar_preference","myValue");
Retrieve variable:
Titanium.App.Properties.getString("myVar_preference"); '// returns "myValue"
Subscribe to:
Posts (Atom)
