FlyPaper

Things that tend to stick

   Mar 09

And Now For Something Completely Different

So, there have been a lot of newsworthy earthquakes this year.  Something must be wrong with the planet right?!   Well as it turns out, according to USGS data, we are seemingly on track to have a normal seismic year.

http://earthquake.usgs.gov/earthquakes/eqarchives/year/eqstats.php


   Feb 19

Damn you Firefox for steppin on my loveley JQuery

So,  jquery is awesome.   But it has it’s setbacks.  Like say you randomly want to position a div off screen for a swoop in from the right,  pretty simple animate call to get it back to the stage $(‘#obj”).animate({“right”: “+=1000px”}, 800);

But now lets say you want to make the nifty animation be invisible and fade in while it makes it’s way merrily across the screen.  Again should be simple $(‘#obj”).fadeIn(0); on $(document).ready and then  $(‘#obj”).fadeIn(800); when you shoot the moon,  but the issue is that you need to hide the object very specifically when you do this or Firefox you’ll need to make sure your object doesn’t leave the DOM (display:none;) by using the fadeOut JQ .  So instead of fadeOut,  you need to implement the .animate() so the object doesn’t sneak off the DOM  $(‘#obj”).animate({“opacity”: “0”}, 0);

Happy Coding.


   Feb 19

Parsing Hashtags in Flash

Today I helped a friend with some top secret mission to parse his twitter in flash.  So here’s how it works

 

First, you’ll need to borrow this package from In Flagrante Delicto  (you won’t need the mxml or flex but his demo is great if you are lookin’ for that kind o’ thing).

Now for my assumptions: 1, you can build an AS 3 Flash doc with a dynamic html text box.  2. You already have a string for your twitter feed XML.

Set yourself up with a as3 flash doc and add a dynamic text field, name it textArea.

You’ll need the following code:

 

package
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.xml.XMLDocument;
    import TwitterString;

    public class Main extends MovieClip
    {
        private var twitterXML:XML; // This holds the xml data
        private var twitterScriptPath:String;
        private var myTwitterID:String;

        public function Main()
        {
            // Put your Twitter username here:
            myTwitterID = "YER_ID"; 

            // Put the path to your script to get the XML feed here:
            twitterScriptPath = "http://www.YERSITE.com/YerFile";

            loadTwitterXML();
        }

        private function loadTwitterXML():void
        {
            var urlLoader:URLLoader = new URLLoader();
            // When all the junk has been pulled in from the url, we'll fire finishedLoadingXML:
            urlLoader.addEventListener(Event.COMPLETE, finishLoadingXML);

            urlLoader.load(new URLRequest(twitterScriptPath + "?twitterId=" + myTwitterID));
            //You can mess with the security sandbox error (or to test locally) by swapping the next line with the one above
            //urlLoader.load(new URLRequest("http://twitter.com/statuses/user_timeline/YER_USERNAME.xml"));        

        }

        private function finishLoadingXML(e:Event):void
        {
            e.target.removeEventListener(Event.COMPLETE, finishLoadingXML);

            // Populate the xml object with the xml data:

            var XMLTwitterDoc:XMLDocument = new XMLDocument();
            var twitterFeed:String;

            XMLTwitterDoc.parseXML(e.target.data);
            twitterXML = new XML(XMLTwitterDoc); 

            showTwitterStatus();
        }

        private function showTwitterStatus():void
        {
            trace("showTwitterStatus");

            // Prep the text field to hold our latest Twitter update:
            twitter_txt.wordWrap = true;
            twitter_txt.autoSize = TextFieldAutoSize.LEFT;

            // Populate the text field with the first element in the status.text nodes:
            var textString:String = twitterXML.status.text[0].toString();

            trace(TwitterString.instance.parseTweet(textString));
            twitter_txt.htmlText = TwitterString.instance.parseTweet(textString);        

        }
    }
}
    public class Main extends MovieClip

    {

        private var twitterXML:XML; // This holds the xml data
        private var twitterScriptPath:String;
        private 

So that’s about it,  other than it being a good idea to save the data in a flash stored object so you don’t overhit the twitter API. 


   Feb 09

Flash Notes: Importing and displaying images via Binary ByteArray

After weeks of sickening trial and error, I have finally figured out a method of importing and displaying ByteArrays as images.

 

To do this, you’ll need the base64 converter library created by the folks at Dynamic Flash available here.

We will continue this under the assumption that you are familiar with class paths and importing external classes.

On to the code:

The full source code is available here: BytaArrayToImage.zip.

There are many methods to get your data, however for this example, we will be using a predetermined ByteArray in an XML file along with some parameters to tell the image where to go and how big to be. This is a very simplified proof of concept, but it will open the door to better things.

package {
    import flash.display.MovieClip;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.*;
    import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.utils.ByteArray;
    import com.dynamicflash.util.Base64;
    import flash.xml.XMLDocument;

    public class ByteArrayToImage extends MovieClip  {

        //xml doc object
        public var mainXML:XML;
        public var theImage:Loader;
        //loader for images.
        var imageLoader:Loader;

        public function ByteArrayToImage(){
            init();
        }

        private function init(){
            digestXML();
        }

        private function digestXML(){
            //build a loader object for the XML file
            var loader:URLLoader = new URLLoader();
            //load the file
            loader.load(new URLRequest("testXML.xml"));
            //once complete, run xmlLoaded function
            loader.addEventListener(Event.COMPLETE, xmlLoaded);
        }

        private function xmlLoaded(evt:Event){
            //create an XML document  to laod the data into
            var mainXMLDoc:XMLDocument = new XMLDocument(evt.target.data);
            //load said data
            mainXML = new XML(mainXMLDoc);
            //parse thru the data and load the images
            for (var i:int = 0; i < mainXML.image.length(); i++){
                // it is important to notice the use of the base64Decoder class on the image string.  This will not work without it.
                loadImage(mainXML.image[i].@imageId, Base64.decodeToByteArray(mainXML.image[i].imageBytes), mainXML.image[i].@xPos, mainXML.image[i].@yPos, mainXML.image[i].@width);
            }
        }

        private function loadImage(imageName:String, imageArray:ByteArray, xPosition:int, yPosition:int, imageWidth:int):void {

            imageLoader = new Loader();
            imageLoader.loadBytes(imageArray);

            var imageToLoad = mainMC;
            imageToLoad.x = xPosition;
            imageToLoad.y = yPosition;
            imageToLoad.width = imageWidth;
            imageToLoad.scaleY < imageToLoad.scaleX ? imageToLoad.scaleX = imageToLoad.scaleY : imageToLoad.scaleY = imageToLoad.scaleX;
            imageToLoad.addChild(imageLoader);

        }

    }
}

   Feb 09

Workin’ the AddThis

Sites like to be shared lately. Since its so cool, they also like to have a thumbnail, title and description.  All this can be controlled (when using AddThis) by adding a link and some meta tags.

Here’s an example.

Paste the following in the <head>

<meta name="title" content="U.S. Cellular Snowman Game" /> <meta name="description" content="U.S. Cellular snowman game description." />

<link rel="image_src" href="<%= Request.Url.GetLeftPart(UriPartial.Path).Replace("/Public/PhotoView.aspx", "") %>/Content/Images/thumbnail.jpg" />

The great part about this is you can independently control the output to your social media outlets.

 

Happy Coding


   Feb 09

.ASHX uploads: The end to file size limitation

So you’ve got a great app that uses an ASP Handler to upload images via a HTTPContext Request.  It’s great, it’s fast but it’s limited by .NET’s assumption that all files on the internet should be less than 4 Mb.  Well the answer lies in the web.config.  A short entry will change the world.

Add this to the <system.web> section.

  <httpRuntime executionTimeout="240" maxRequestLength="10000" />