AS3: Play embedded flv

Playing an embedded FLV file in AS3 is something I keep seeing asked in forum after forum. (I know because I checked about 20 looking for the answer.)

Note: The onMetaData and onXMPData functions are required to be defined in this class.

After digging around for awhile I found a solution using Video and NetStream, here we go…

ActionScript 3
package {
import flash.display.AVM1Movie;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.utils.ByteArray;
 
**
* ...
* @author John Fly
*/
public class Main extends Sprite {
 
[Embed(source='../assets/demo.flv',mimeType='application/octet-stream')]
private var myOpening:Class;
 
public function Main():void {
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
 
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var myOpeningBytes:ByteArray = new myOpening();
 
var vid:Video = new Video(640, 400);
addChild(vid);
 
var nc:NetConnection = new NetConnection();
nc.connect(null);
 
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.play(null);
 
vid.attachNetStream(ns);
 
ns.appendBytes(myOpeningBytes);
 
}
 
public function onMetaData(info:Object):void {
trace("width: " + info.width);
trace("height: " + info.height);
}
 
public function onXMPData(info:Object):void { }
 
}
 
}

WCF Data Services : Returning complex types

Since I store data and time information in a sql database in seperate date and time columns, both using DateTime, I wanted a WCF Data Service to return on the true portion of the values, (ToShortDateString and ToShortTimeString).

I tried using the built in query projection functions but those don’t work that way, I then tried to return a plain List<T> of a new class that looked like my entity except for having String types instead of the DataTime types, and I would populate those members with the proper ToXXXXXString method.

That however failed with : Unable to load metadata for return type

I then found out that the WCF Data Service must return a type defined in the entity model, this is because the service contract is defined using the entity model itself.

After reading a post by Sam Mueller : 

http://samuelmueller.com/2009/11/working-with-projections-and-dtos-in-wcf-data-services/

I created a complex type, and first had to select out my data, perform a foreach on the records, populate a List<T> of my newly created complex type.  This allowed me to do the necessary data modifications prior to returning the data, and everything on the client side performed without modifications.

PBE : Community built component

Wanted to create an area to discuss writing a component for PBE with some others.

If you have any ideas for a component you would like to work on let me know, we can try and build something simple but useful.  Something targeted to helping the community and others getting started with PBE.

I started a thread on the PBE forums on this as well : http://pushbuttonengine.com/forum/viewtopic.php?f=8&t=725

Back up after web host issues

So the blog was down for two weeks when webhost4life moved me to their new platform.

It was awful.

For two weeks I tried to work with their tech support to get two domains working, this one and my geekhealth.org site, but no luck.

After just 20 minutes with arvixe.com and I’m back up and running.

 

If you thinking about using webhost4life, I’d give them awhile until they settle out their issues with their new systems.  One of the issues I was running into included extremely slow response on their “IIS Panel” which would lead to timeouts.  Their response was to wait a month or two until they added some new servers.

Overall I’m quite pleased with arvixe and their control panel.  It let me setup two domains quickly and was very explicit in setting up new application roots and virtual directories, something webhost4life’s new system does not excel at.

Flash game development: PushButton Engine

Well, I’m starting to mess with flash.  I thought I would get into it by starting with some game development.

I looked around and found flixel an open source game library/engine and I must say, it was very easy to start up a basic game project.  After getting the basics down though, I found that I wanted more control, and didn’t really want to use flixel’s built in components for my projects.  They were great for certain types of games, but I wanted something different.

I started looking again and came across PushButton Engine(PBE), I’ve played with it for a week or two now and really like it so far.  PBE comes from the same people that helped make the Torque game engine, which is pretty awesome.  So right up front that got my attention.  The engine is open source, and the company (PushButton Labs), plans to monetize the platform my offering “premium” plugins which they refer to as components.  In my mind this is a wonderful strategy, and something I can get behind.

I’m just moving past their published tutorials, and starting to work on a tower defense game of my own.  I’ll start tracking it here in hopes that others can learn from my trials and experiments.

ESXi ssh access

This morning I had to force a guest in an ESXi host to restart (Windows Server 2008) when it hung applying a patch.

ESXi does not support ssh connections out of the box, so you have to edit a file on the ESXi host first:

1. Go to the ESXi console and press alt+F1
2. Type: unsupported
3. Enter the root password(No prompt, typing is blindly)
4. At the prompt type “vi /etc/inetd.conf”
5. Look for the line that starts with “#ssh” (you can search with pressing “/”)
6. Remove the “#” (press the “x” if the cursor is on the character)
7. Save “/etc/inetd.conf” by typing “:wq!”
8. Restart the management service “/sbin/services.sh restart”
10 – Kill inetd : kill `ps | grep inetd | cut -f2 -d” “‘
11 – Start inetd: inetd

I found this article very helpful : http://www.yellow-bricks.com/2008/08/10/howto-esxi-and-ssh/

ASP.NET Buttons not causing postback

I came across this yesterday, and thought it might help someone else (or myself in the future).

While working on an exising web form (that used the ajaxtoolkit) I suddenly realized that some of my existing buttons were no longer causing postbacks properly.  Unfortunately I had worked on two seperate issues before testing all existing functionalty so I did not immediately realize what new code may have broken the form.

It ended up being a RequiredFieldValidator on a hidden panel.

Once I set the correct controls to CausesValidation=”false” everything started working again.

Geekhealth.org

Well, I’ve updated another site I run to use blogengine.net.  Geekhealth.org was something I came up with awhile back.  And here is a quick rundown of how it came to be.

When I first came up with the idea, I didn’t have much ASP.NET, HTML or CSS experience at all.  All my work professionally to that point was backend data processing or Windows Forms. I decided that it would be good for me to learn some front end web skills.  I learned about CSS and semantically correct markup and off I went, coding up pages of CSS and trying my hand at graphics editing. 

The results, while valid XHTML were did not receive good reviews.  I then turned to themeforest.net and purchased what looked like a good site template for $15.  It turned out to be a good idea.  Since I had separated my data and presentation using CSS it was pretty easy to switch from my site layout to the new template from themeforest. 

The problem was that I had to write a new ASP.NET page for any updates I wanted and this was not quick.  After implementing blogengine.net here, I decided to move to it for geekhealth.org as the main way to add new information and articles.

Again the transition was pretty smooth.  I took my site template and following the video tutorial from Al Nyveldt I quickly created a custom blogengine.net theme out of my existing site.

Once the site was functional and had the look I was going for I downloaded and installed yetanotherforum(YAF 1.9.403beta), which is an ASP.NET open source message board.  I installed the forum as a folder in my website and using winmerge, I was able to merge the YAF web.config with my geekhealth.org web.config and then set YAF to use my existing database for membership and roles.

Over all it took just over five hours to take my existing site and integrate with blogengine.net and YAF.  I am very pleased with the results and now I have a site that is much easier to update, and has single sign on for all parts.

The main lesson learned what that by “correctly” coding my site to be independent of the presentation(CSS) I was able to quickly perform site wide updates without much trouble.

Many thanks to the blogengine.net team and the yetanotherforum team for making two great and free products!

MSSQL Sparse Columns (pt2)

Follow up from : http://johnfly.com/blog/post/MSSQL-Sparse-Columns-(pt-1).aspx

Well I went and wrote a smal WPF app to go over my tables and show my columns for every table along with the percantage of NULLS in each column.  I also display the suggested percent of NULL columns suggested for a forty percent savings for the column data type.

The results are remarkable, my data size went from 1.43GB to 1.00GB!

I’m going to keep the changes in test for awhile before moving them to production so I won’t have any performance impact numbers yet but I will post when I have them.

 

The WPF app is very poorly done, but functional, if anyone wants it here it is:
SparseColumn.zip (1.02 mb)

It also uses the WPF Toolkit DataGrid found here :
http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-datagrid-feature-walkthrough.aspx


MSSQL : Sparse Columns (pt 1)

My last session of the entire conference might prove to be the one that has the most immediate impact when I get back to work.

Kimberly Tripp went over MSSQL sparse columns and filtered indexes.  Both of these are features I’ve considered using in the past but sparse columns were new and I didn’t have a good source of information on their use and how they might work for a project of mine.  Filtered Indexes are something I’ve read about but did not fully respect the impact of their use.

Sparse Columns :

In a nutshell sparse columns are useful because they take up no space *if* the value is empty(NULL). There are of course caveats, if there is a value in the column(non-null), it is going to consume four(4) more bytes than is normal for that data type. BOL (http://technet.microsoft.com/en-us/library/cc280604.aspx) has charts that can help you figure out if your columns might benefit from being sparse.  I’ll be investigating sparse column use in a large data table I have at work and I’ll report back the impact in space and performance.