This is my first post from a phone. I recently got a new android phone and am loving it. If you are in the market for a new phone you’ve got to look into an android device. I’m planning to do some more android development and will keep you informed.
Random Vector and Random Array Functions
I’ve been working on a Blackjack game and have needed to do a lot of shuffling, cards that is. I’ve seen quite a few shuffling functions over the years. Here is the one I like, partly because I wrote it. Well okay I took what I liked in the others and modified them to come up with these:
public static function randomArray(src:Array):void { var len:uint = src.length; for(var i:int=len-1; i>=0; i--) { var randIndex:uint = randomUint(0, len-1); var temp:* = src[randIndex]; src[randIndex] = src[i]; src[i] = temp; } }
Vector version looks like this:
public static function randomVector(src:*):void { var len:uint = src.length; for(var i:int=len-1; i>=0; i--) { var randIndex:uint = randomUint(0, len-1); var temp:* = src[randIndex]; src[randIndex] = src[i]; src[i] = temp; } }
Here is a sample of how the vector version is used:
Randomize.randomVector(cards as Vector.<Card>);
Here is the randomUint function that it uses:
public static function randomUint(min:uint, max:uint):uint { return Math.random()*((max+1)-min)+min; }
I like to call these functions a random number of times so that the deck of cards is nice and shuffled. Enjoy!
7 Foods That Are Good For Your Body And Your Brain
Since I’m on the topic of health today I want to share one more tidbit I just read. I’m a big fan of the P90X program and just read an article from the beachbody.com website entitled 7 Foods That Make You Smarter by Suzy Buglewicz. Great article, go read it when you have a chance. I just wanted to list the 7 foods it mentioned here on my blog since they are some of my personal favorites. Here they are:
- Spinach
- Oatmeal
- Fish
- Walnuts
- Berries
- Yogurt
- Eggs
10 Healthy Diet Principles
I would dare say that when most people think of a typical programmer they think of a nerdy person who sits at their desk all day. And sitting at your desk all day can lead to being unhealthy both in diet and exercise.
Okay first let me start by saying that this is not the typical post for me. It has nothing to do with computers and is probably a stretch from what is commonly believed about computer programmers. I would dare say that when most people think of a typical programmer they think of a nerdy person who sits at their desk all day. And sitting at your desk all day can lead to being unhealthy both in diet and exercise. For the record, if I’m nerdy it’s definitely a cool version of nerdy and as far as diet and exercise go I believe strongly in both. I listened to an audio book recently called the Body Fat Solution by Tom Venuto and it totally changed my view of diet and exercise. I have been fairly healthy all of my life, but have never really thought too much about how what I eat effects my quality of life. Anyway I don’t want to ramble on about that as it is a big topic and there are many more qualified experts that can address it far better than I. I do highly recommend reading that book. In the book there is a list of ten diet principles that I think are important for everyone. Here they are
- Focus on the calorie deficit first and budget calories wisely
- Start building every meal with lean protein
- Eat vegetables (fibrous carbs) with every meal
- Eat omega 3 and other healthy fats every day
- Eat at least 2 Fruits every day
- Eat natural starches and grains as your x factor
- Eat mostly foods that pass the natural test
- Eat 5 to 6 times a day (a meal or a snack every 3 hours)
- Limit or avoid liquid calories and drink mostly water or green tea instead
- Follow the 90/10 rule
If you have any questions leave a comment or go check out the book. I got the book off of audible.com or you can go to their website: http://www.thebodyfatsolution.com/
How do I change the retry time in SmartFTP
So if you do much with ftp you have probably heard of SmartFTP. If not I would highly recommend them. I have used a variety of ftp programs and theirs is by far the best that I have used up to now. It has a lot of great features and is reasonably priced. If you have used it then you have also most likely ran into the issue that arrives if you attempt to upload a file and it fails causing it to state that it will retry at (time stamp) future. The default is 30 seconds from the time that it attempted to upload the file. Well for me the problem is 30 seconds is much more than I care to wait. I do a lot in Adobe Flash and I have SmartFTP set to monitor the .swf file for the .fla file that I am working on. This way every time I publish the file it will automatically upload it for me. The problem is that SmartFTP recognizes the file having been changed right as Flash begins to compile the swf not when it is actually finished. This means that every time I would have to wait 30 seconds. Well there is a solution and here it is. To change the retry default time value go to Favorites > Edit Favorites. In the Favorites window, go to Tools > Edit Default Favorite. In the Properties window, select the “Connection” menu, and there you will see a setting “Retry Delay” it is set to 30 seconds by default. There you can type in whatever time you want. For most small swf files 1 second has worked for me.
How to embed fonts using actionscript 3
This was causing my to bang my head for a little while. There are different ways depending on whether you are using Flash or Flash Builder (previously Flex Builder). If you are using Flash you can go here for a good example/tutorial: http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/. Basically you add a font to the library by clicking the pop-up menu (in the upper-right corner of the Library panel), export it for actionscript and then give it a class name. After that your code looks something like this:
var myFont:Font = new Font1(); var myFormat:TextFormat = new TextFormat(); myFormat.font = myFont.fontName;
Embedding fonts in AS3 seems to be a big problem for many people out there especially if you are using Flash Builder/Flex Builder. I know it was driving me crazy! I was following the examples, but still seemed to keep getting the same error: “An Embed variable must not have an existing value.”. Okay maybe it’s just me but that one was a little cryptic. Finally after a long time, but before having to do a Google search for straight jackets I figured out what I was missing. In all of the examples the embed line was right above a Class variable, but mine was not, so I added one and cha ching it worked. Here is a sample:
[Embed(source="assets/MONACO.TTF", fontName="monaco", mimeType="application/x-font-truetype")] private var MonacoFontEmbed:Class;
It may just be me but this was not obvious I must confess. You don’t use that variable at least I didn’t, you simple set the .font property to the fontName value. It looks something like this:
myFormat.font = "monaco";
monaco is what I named it. You can name that whatever you want along with the variable. I named it MonacoFontEmbed, but you can name it whatever. I hoped this helped. If you have any questions feel free to post them. Embedding fonts is very useful especially if you are planning to manipulate a text field. Manipulations like rotation will just cause your text field to disappear if created dynamically and without embedding the font.
W3C Page Validation Issue
It’s good practice to always make sure that each page on your site validates to its proper doctype. Recently I noticed that some pages on a site I did that use to validate no longer did. It was giving me an error saying that it didn’t know how to decode Content-Encoding ‘none’. This was saying that I wasn’t declaring the encoding at the top of my page. The thing is I was. Here is what the problem was. I am using php and have an external php page that contains functions on it that are used by the page and I was including that page at the top of the document. The problem with this was that it was above the doctype declaration. All I had to do was move it down one line and that fixed it. I’m not sure if something has changed with the validation because it use to validate, but if you run into this problem just move it down one line. Here is an example:
Before:
<?php include_once(“my-file.php”);?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
After:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<?php include_once(“my-file.php”);?>
PS
I use a cool plugin for Firefox called Web Developerthat has a built-in tool that will validate your page straight from the W3C Validator. If you are not currently using this I suggest checking it out!
Apple vs Adobe
Last week I heard the news that Apple is looking to only accept apps that were created using their software. This means that the new feature in Flash CS5 that allows you to publish apps for the iPhone might not be an acceptable method for making apps. I think that this is a big mistake by Apple and a slap in the face to Adobe. Coming from someone that has taken many an Art and Multimedia class at the university I feel that it is fair to say that Adobe was one of the key factors that kept Apple desktops alive. When no one was buying Apple desktops Art departments in schools all across the country still were. For some reason many an art department thought that Macs were better when it came to creating art. The article that I read was from Lee Brimelow. You can read it here: http://theflashblog.com/?p=1888 I am really curious to see what others are thinking. Please comment and let me know.
The Top 5 Reasons to upgrade to CS5
So since the unveiling of CS5 last week I have been doing a little research and have come up with the top five reasons to upgrade to Adobe CS5.
- CS5 now includes Flash Builder (formally Flex Builder)
- You can now create a Flash project that can be coded in Flash Builder
- You can use Flash to create apps for the iPhone and iPad
- Content Aware Fill in Photoshop
- Content Aware Fill in Photoshop
If you haven’t seen Content Aware Fill in Photoshop CS5 you need to. Go to John Nack’s blog and check it out. Here is a link: http://blogs.adobe.com/jnack/2010/03/caf_in_ps.html
Flash Builder 4 Install Error
So I attempted to install the new Flash Builder 4 the other day and got this error:
Exit Code: 7
————————————– Summary ————————————–
– 0 fatal error(s), 3 error(s), 0 warning(s)
ERROR: Custom Action for payload {177E1CA1-14CC-4398-AB15-A5746EFE8F22} Adobe Flash Builder returned error. Failing this payload.
ERROR: The following payload errors were found during install:
ERROR: – Adobe Flash Builder: Install failed
————————————————————————————-
00-37641-141726032010
I am running a 64 bit version of Windows 7 that easily met the requirements so it was throwing me for a loop. After looking at the install log file a good friend of mine noticed that my windows user name had a special character in it (the ‘&’) and suggested that I make a new admin user without any special characters in the name. I did that and it worked. If you run into this error and are banging your head against the wall check your user name. Thanks again Josh for the find! You can check out Josh’s blog by clicking the link I have to it on my blog.