PaperVision3D RSS Reader Alpha

November 15th, 2008 by Brendon Smith

Well I have been working on an RSS feed reader that is papervision3d based it is still nowhere near where I would like it to be. I have about a slew of other ideas on how to improve this project and I am just getting started that is why it is an alpha. I have a great deal of code refactoring to do so as a result I will not be sharing the code. I have thought about this project for sometime. I love papervision3d and I think out of all the as3 library’s out there for 3D code this is the weapon of choice for me. It has a so many features that it is impossible to list them all on this blog post. I have also been playing around with SWX and really looking forward to an as3 version of it. I am well aware of the flash.net Local connection library but with the latest version of the flash player and new security settings I have shied away from using it with as3 Papervision3d code. I have also been thinking about redoing this project using an earlier version of PV3D. The great white beta is awesome love it and I am not sure if my time is better spent working on an older version that may run as2 or working on improving Papervision3d itself. I have noticed it’s response to planes that are textured with dynamic text can be difficult for example if I amp up this feed reader to over 20 posts it crashes. I am looking forward to the opportunity of maybe finding some fixes for these problems myself. I discovered this issue while populating it with 40 blog posts to render at one time. The code runs an array that is populated with the xml using a for loop and push in as3 the reason why I did not combine the for loop xml and the actual creation of the posts is due to the bitmap error I am currently recieving in PV3D2. One way I could improve this code is to create an object that contains all the feed data and create a timer that slows down the actual execution of the code so that papervision3d has enough time to apply the textures to the planes. I would also like to add some special effects papervision3d allows you to wrap your displayobject3d’s with an effects layer that makes for some ridiculously cool effects. So please don’t take this as a finished product I have hear because it is not! I have also thought about creating a feed reader that has cubes with movie textures that are created to house all the text (as in all 40 posts). I could do this by dynamically creating the movies in an array of Movie Materials that are interactive this way I would not have to clog the PV3D side of the code. I may choose to go that route in the near future. It is fun to work on these projects and It helps keep my mind sharp. I throughly enjoy creating stuff and use these experiments both to help me on my new portfolio and my OOP skills in general. I find this stuff fun and exciting if you can believe that. I get a real kick out of doing something new! I will also be redoing this project in Silverlight using Kit3d. The reason for this is simple because I can. I don’t really believe in saying one technology is better than the other. I just really like to play with all technologies and want to learn something new. I guess I am technologically agnostic. I just want an end result one that can be viewed on any computer with the same result and that is usually difficult thanks to Microsoft technologies but they have been making strides to make silverlight play well on all computers and I like the ability to use C# as an option not to mention the DLR with Silverlight.


PaPaperVision3D RSS Reader Alpha Click Here

So what have I been up too? Well building a new computer for starts my AMD died and it was my Ubuntu box. Instead of going out there and purchasing a computer I have decided to put it together myself. I have 90% of the parts now. I should have it completed in the next 3 weeks. It will run Ubuntu/Vista on a dual boot 1.5 terabyte hard drive, Quad Core, 16gb RAM, in a shell that lights up and looks like HAL9000. I will also continue working on my flash experiments and polishing them I would like my new portfolio to resemble CompizFusion Ubuntu I will utilize as3 and silverlight2 to do this. I would like to create one version using Silverlight and the other in as3. I want them to be as similar as possible displaying both technologies and allowing the user to pick which version they would like to see. It is one of my more ambitious projects to date. Things at work are going well I love working on Salesgenie.com and I am fortunate to work with exceptionally bright and passionate people that I am constantly learning from! So my skills have been improving rapidly! I am also ready for winter to set in. I have a plethora of books to consume and numerous magazines piling up and begging my attention! This winter won’t all be technical jargon though I have to throw in some art and literature to be a full rounded person you know. Tomorrow at the Joslyn I am going to see Diego Rivera you know Frida’s husband and looking forward to it. On a side note I found this video on Youtube of Joshua Davis thought I was way cool really like his work!

I will also be working on improving my exceptionally simple generative art application. I have been thinking of numerous ways I can and will improve it in the near future. The feed reader in Papervision3d and the generative art application will eventually be apart of my new Portfolio once they are polished and as you can see they are both along ways from that. This stuff takes time and their never seems to be enough time in the day. Oh well I know the weather is getting cold and that gives me a good excuse to polish my work!

What I have been reading lately:

4X4 Life and Oblivion
Robert Penner
Mathographics Recommended by the Flash Blog

Cool Librarys of Code:
Flare
Birds Eye
PaperVision3D

Cool Posts:
Flash Mathographics
gSkinner Flash Audio Demo

Using ScaleNine Skins in Flash Develop3

October 30th, 2008 by Brendon Smith

Have you ever wanted to use a Scale Nine Skin in your Flash Develop environment? Well its easy. Here is an example you can download. Here are few easy steps to accomplish your goal:

  • Install Flash Develop by Downloading it here.
  • Configure your compiler and download the Flex SDK if you haven’t yet.
  • Go to Scalenine.com find a skin.
  • Now create a new Flex Project AS3.
  • Connect all libraries or SWC by adding them to the project.
  • Go through the css and make sure everything is linked to the correct asset, image, etc.
  • Copy the MXML in the sample and place it in the Main.mxml of your project.
  • Now build. It’s that easy.


So now you can examine the template and modify it if you like. It is a fairly painless process and with flash develop you can now see how to use the skin with the default .mxml file. So that should be enough to get you working on building cool interfaces for your flash develop project. You can see this example here and you can download the flash develop project here.

Links of Interest:
Flash Develop
ScaleNine
Silverlight Skins
Flash Develop Project Files to Download

Silverlight 2 RSS Reader

October 26th, 2008 by Brendon Smith

Well here it is I have been playing around with Silverlight2 and it is astronomically better than Silverlight1!  This is an extermly simple feed reader with no design add more or less a proof of concept.  I have been trying to do things in ActionScript and the do them in C#/SilverLight.  I have leaned a great deal I have been studying the Silverlight Samples and found a feed reader.  I got it installed it worked well but then I decided it would be better if I could add a combo box drop down that has options for the user So I went ahead and created one while doing this I also studied some more examples from Scott Guthrie’s (Maybe he should rename his blog Scott Gu to Guru) blog.  So some of this example is just ASP.NET / C#.  I found the necessity of crossxml kind of a pain but a necessary pain.  So I have included an example of a clientaccess.xml with the source.  I found Blend to be a little wonky namely I ran in to an issue with the Service Pack1 install you can read about that issue here.  Although I don’t believe to many people will run into the same issue because Microsoft has resolved the issue.  I find the integration between Blend and Visual Studio a little wonky but tolerable.  I have also noticed for newbies who want to get started Microsoft has finally release a one click installer of their own otherwise known as the Microsoft Web Platform.  So if you want you can install it and use it with this project.  Here are a few of the numerous ways I can improve this feedreader add design make it look good. Create a webservice that allows for the input of the feeds and stores them in a database remove the Feeds.xml file and replace it with a database connection. Allow the database to input the Feed information and purge old information this would be better and it would resolve those tedious crossxml issues with silverlight. Little code snippet note you should download the whole project or this snippet really won’t do you any good.

        public string myURL;
        WebClient client = new WebClient();
        public Page()
        {
            InitializeComponent();
            XDocument feedXML;
            feedXML = XDocument.Load("Feeds.xml");
            var feeds = from feed in feedXML.Descendants("Feed") where feed.Attribute("status") == null || feed.Attribute("status").Value != "disabled" select new FeedDefinition { Name = feed.Element("Name").Value, Url = feed.Element("Url").Value };
            foreach (var feed in feeds)
            {
                feed.Name.ToString();
                feed.Url.ToString();
            }
            ddlFeeds.ItemsSource = feeds;
 
        }
 
            itemsList.Visibility = Visibility.Collapsed;
            itemContent.Visibility = Visibility.Collapsed;
            object myFeed = ddlFeeds.SelectedItem;
            FeedDefinition MyFeed = new FeedDefinition();
            MyFeed = myFeed as FeedDefinition;
            myURL = MyFeed.Url;

Somethings I will point out with silverlight it’s runtime is a 5.8mb download in comparison to Flash Player being 1.8mb.  One thing that Silverlight allows you to do is leverage DirectX on the users computer but as you and I know DirectX will only work  for Microsoft compatible operating systems.  Which is a buzz kill I think they should have leveraged OpenGL or Both.  So in short you won’t get the same experience cross operating systems.  Linux has been working on Moonlight and Microsoft is supporting Eclipse for Silverlight so those are pluses.  One thing that is nice about Silverlight is the ability to create WPF applications and deploy them with a Click-Once install:)  This is extremely similar to Adobe’s Air platform.   One excellent example I have been studying is Microsoft’s UniveRSS WPF application excellent example of an RSS feed reading using directX 9!  So check it out here.  You can also find numerous other examples of Silverlight/WPF out in the wild already like this cool Facebook application.  So in all I have mixed feelings about silverlight and I will continue to explore it and utilize it. I think flash users will be upset because they won’t have support for all the cool adobe effects built in but I don’t believe it will be long before users start writing code for similar effects and then share them on codeplex. I have been working on various experiments and then redo my Portfolio site in both Silverlight and Flash.


In other news I have been working on my Papervision3D project and it is getting better not finished but closer.  It was a beautiful fall weekend here and Lisa and I got out and took numerous photographs.  I took several panoramic in Memorial Park maybe I will post them sometime soon. I have also been working on constructing my new computer that I am going to name HAL 9000 it is a Quad Core with a great deal of horse power will crush any apple when I am done with it.  Will be a dual boot with Ubuntu / Vista Ultimate! I am going to have 1.5 terabytes worth of hard-drive space:)

My Ridiculously Simple Feed Reader Code Download Click Here

Links of Interest:
Shine Draw
Silverlight Code Examples
Popfly Widget Maker
Silverlight and the Combo Box
ScottGu’s Blog Excellent Place to learn Silverlight
UniveRSS
Visual Sage / Facebook App

Generative Art With Kuler

October 13th, 2008 by Brendon Smith

Computer Art starts with Computer Arts magazine.  I highly recommend a steady dose of Computer Arts magazine and Friends of Ed publications to any aspiring developer / designer.  It will open your eyes to a whole new world of possibilities and truly set your imagination free. Let me first mention http://visualrinse.com Chad Udell he recently wrote a tutorial for Computer Arts you can find it here this example really caught my eye!  I have made the following modifications to it.  Placed several flash movies in an array and allow them to inherit the color choices provide by Kuler.  I have also enabled the users to save their creations as an image.  I use the Flash Core library which you can download here -> http://code.google.com/p/as3corelib/.  Please note I used php on my server but you might find better results using ASP.NET and C#.  It seems on my server if your image has 40 or less objects rendered your chances of saving it properly are higher.  I am sure I could go through the server logs and trace down the exact problem.  Let me just say this allowing the designer to create flash movies that populate the screen opens lots of other possibilities for your creations.  Imagine the following scenario you could have a Radio Button list and the list could represent movements in art like -> Abstract Expressionism, Impressionism, or Cubism. Once the user selects the style of choice you could allow them to generate a new work of art based off of the users style of choice.  This is exactly what I plan to do with my Kuerl-Splash based off of Kulercreator in the future.  Anyway it is a fun experiment.

Here is the flash code:

[-]View Code ACTIONSCRIPT
//Frame 1:
import flash.display.Graphics;
import flash.display.*;
import flash.display.Stage;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilter;
import flash.filters.BitmapFilterType;
import flash.filters.BlurFilter;
import flash.filters.BevelFilter;
import fl.controls.Button;
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
import fl.controls.TextInput;
import flash.utils.getDefinitionByName;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.FullScreenEvent;
import flash.geom.ColorTransform;
import flash.external.ExternalInterface;
import com.adobe.images.JPGEncoder;
 
 
//import Zeh Fernando's excellent Tweener package
import caurina.transitions.*;
 
var numBasicDots:Number = 25;
title_txt.visible = false;
url_txt.visible = false;
 
var currentThemeTitle:String;
var dynamicColorArray:Array = new Array();
var numCirclesToGen:Number;
 
//my favorite little random function - seed it with floor and ceiling and it brings back a random interger from the range
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
 
function randRange2(min:Number, max:Number):Number {
var randomNum1:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum1;
}
function splatRange(min1:Number, max1:Number):Number {
var randomSplat1:Number = Math.floor(Math.random() * (max1 - min1 + 1)) + min1;
return randomSplat1;
}
 
var myBasicTimer:Timer = new Timer(200);
myBasicTimer.repeatCount = numBasicDots;
myBasicTimer.addEventListener("timer", timedFunction);
myBasicTimer.addEventListener("timerComplete", timerCompleteFunction);
 
 
// Function will be called every 500 milliseconds
function timedFunction(eventArgs:TimerEvent) {
removeChild(getChildByName("dot"+(myBasicTimer.currentCount-1)));
removeChild(getChildByName("splat"+(myBasicTimer.currentCount-1)));
}
 
function timerCompleteFunction(eventArgs:TimerEvent) {
play();
}
 
function kulerCreator() {
var Splat1:Splater1 = new Splater1();
var Splat2:Splater2 = new Splater2();
var Splat3:Splater3 = new Splater3();
var Splat4:Splater4 = new Splater4();
var Splat5:Splater5 = new Splater5();
var Splat6:Splater6 = new Splater6();
 
var arraySplat:Array = new Array();
arraySplat.push(Splat1,Splat2,Splat3,Splat4,Splat5,Splat6);
// Create blur filters to apply to the circles drawn.
var blur1:BlurFilter = new BlurFilter();
blur1.blurX = 100;
blur1.blurY = 100;
blur1.quality = BitmapFilterQuality.MEDIUM;
 
var blur2:BlurFilter = new BlurFilter();
blur2.blurX = 3;
blur2.blurY = 3;
blur2.quality = BitmapFilterQuality.MEDIUM;
 
var blur3:BlurFilter = new BlurFilter();
blur3.blurX = 12;
blur3.blurY = 12;
blur3.quality = BitmapFilterQuality.MEDIUM;
 
var blur4:BlurFilter = new BlurFilter();
blur4.blurX = 50;
blur4.blurY = 50;
blur4.quality = BitmapFilterQuality.MEDIUM;
 
var blurArray:Array = new Array([blur1], [blur2], [blur3], [blur4]);
 
var colorArray:Array = new Array('0x026109', '0x037F0C', '0x5BB520', '0xAAD70E');
 
 
for (var i:Number=0; i<numBasicDots; i++) {
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(colorArray[randRange(0,colorArray.length)], Math.random() );
mySprite.graphics.lineStyle(randRange(0,30), colorArray[randRange(0,colorArray.length)], Math.random(), true);
var currRand:Number = randRange2(1,300);
mySprite.graphics.drawCircle(randRange2(0,stage.stageWidth), randRange2(0,stage.stageHeight+100), currRand);
mySprite.filters = blurArray[randRange(0,blurArray.length)];
mySprite.alpha = 0;
mySprite.scaleX = 0;
mySprite.scaleY = 0;
this.addChild(mySprite);
mySprite.name = "dot"+i;
Tweener.addTween(mySprite, {alpha:1, _scale:1, time:randRange(0,5), transition:"easeOutSine"});
}
 
//Split for easy seperation later
for (var i:Number=0; i<numBasicDots; i++) {
//Use color transform and assing it the color values start with white values on your movie
var myFreakinColor:ColorTransform;
myFreakinColor = new ColorTransform();
myFreakinColor.color = colorArray[randRange(0,colorArray.length)], Math.random();
var Splat1:Splater1 = new Splater1();
Splat1.name = "splater"+i;
Splat1.transform.colorTransform = myFreakinColor;
var Splat2:Splater2 = new Splater2();
Splat2.name = "splater"+i;
Splat2.transform.colorTransform = myFreakinColor;
var Splat3:Splater3 = new Splater3();
Splat3.name = "splater"+i;
Splat3.transform.colorTransform = myFreakinColor;
var Splat4:Splater4 = new Splater4();
Splat4.name = "splater"+i;
Splat4.transform.colorTransform = myFreakinColor;
var Splat5:Splater5 = new Splater5();
Splat5.name = "splater"+i;
Splat5.transform.colorTransform = myFreakinColor;
var Splat6:Splater6 = new Splater6();
Splat6.name = "splater"+i;
Splat6.transform.colorTransform = myFreakinColor;
var arraySplat:Array = new Array();
arraySplat.push(Splat1,Splat2,Splat3,Splat4,Splat5,Splat6);
var mySplat:MovieClip = arraySplat[randRange(0,5)] as MovieClip;
mySplat.transform.colorTransform = myFreakinColor;
mySplat.filters = blurArray[randRange(0,blurArray.length)];
mySplat.alpha = 0;
mySplat.scaleX = 0;
mySplat.scaleY = 0;
mySplat.x = (randRange(0,stage.stageHeight+100));
mySplat.y = (randRange(0,stage.stageWidth+100));
this.addChild(mySplat);
mySplat.name = "splat"+i;
trace(mySplat);
Tweener.addTween(mySplat, {alpha:1, _scale:1, time:randRange(0,5), transition:"easeOutSine"});
}
//instantiate the UI onto the stage.
var ui = new creatorUI();
this.addChild(ui);
}
 
kulerCreator();
 
stop();
 
//Frame2
 
Frame2:
 
title_txt.visible = true;
url_txt.visible = true;
 
 
deleteButton_mc.visible = false;
saveImageButton_mc.visible = false;
var Sketch_mc:Sketch = new Sketch();
addChild(Sketch_mc);
function kulerCreatorLive() {
// Create blur filters to apply to the circles drawn.
var blur1:BlurFilter = new BlurFilter();
blur1.blurX = 1;
blur1.blurY = 1;
blur1.quality = BitmapFilterQuality.MEDIUM;
 
var blur2:BlurFilter = new BlurFilter();
blur2.blurX = 3;
blur2.blurY = 3;
blur2.quality = BitmapFilterQuality.MEDIUM;
 
var blur3:BlurFilter = new BlurFilter();
blur3.blurX = 12;
blur3.blurY = 12;
blur3.quality = BitmapFilterQuality.MEDIUM;
 
var blur4:BlurFilter = new BlurFilter();
blur4.blurX = 50;
blur4.blurY = 50;
blur4.quality = BitmapFilterQuality.MEDIUM;
 
var blurArray:Array = new Array([blur1], [blur2], [blur3], [blur4]);
 
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
 
function randRange2(min:Number, max:Number):Number {
var randomNum1:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum1;
}
 
for (var i:Number=0; i<numCirclesToGen; i++) {
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(uint("0x" + dynamicColorArray[randRange(0,dynamicColorArray.length)]), Math.random() );
mySprite.graphics.lineStyle(randRange(0,30), uint("0x" + dynamicColorArray[randRange(0,dynamicColorArray.length)]), Math.random(), true);
mySprite.graphics.drawCircle(randRange2(0,stage.stageWidth), randRange2(0,stage.stageHeight), randRange2(1,300));
mySprite.filters = blurArray[randRange(0,blurArray.length)];
mySprite.alpha = 0;
mySprite.scaleX = 0;
mySprite.scaleY = 0;
mySprite.name = "liveDot" + i;
 
Sketch_mc.addChild(mySprite);
Tweener.addTween(mySprite, {alpha:1, _scale:1, /*x:randRange(0,stage.stageWidth-(mySprite.width/2)), y:randRange(0,stage.stageHeight-(mySprite.height/2)),*/ time:randRange(0,5), delay:i*0.25, transition:"easeOutSine"});
}
for (var i:Number=0; i<numCirclesToGen; i++) {
var myFreakinColor:ColorTransform;
myFreakinColor = new ColorTransform();
myFreakinColor.color = uint("0x" + dynamicColorArray[randRange(0,dynamicColorArray.length)]), Math.random();
var Splat1:Splater1 = new Splater1();
Splat1.name = "splater"+i;
Splat1.transform.colorTransform = myFreakinColor;
var Splat2:Splater2 = new Splater2();
Splat2.name = "splater"+i;
Splat2.transform.colorTransform = myFreakinColor;
var Splat3:Splater3 = new Splater3();
Splat3.name = "splater"+i;
Splat3.transform.colorTransform = myFreakinColor;
var Splat4:Splater4 = new Splater4();
Splat4.name = "splater"+i;
Splat4.transform.colorTransform = myFreakinColor;
var Splat5:Splater5 = new Splater5();
Splat5.name = "splater"+i;
Splat5.transform.colorTransform = myFreakinColor;
var Splat6:Splater6 = new Splater6();
Splat6.name = "splater"+i;
Splat6.transform.colorTransform = myFreakinColor;
var arraySplat:Array = new Array();
arraySplat.push(Splat1,Splat2,Splat3,Splat4,Splat5,Splat6);
var mySplat:MovieClip = arraySplat[randRange(0,5)] as MovieClip;
mySplat.transform.colorTransform = myFreakinColor;
mySplat.filters = blurArray[randRange(0,blurArray.length)];
mySplat.alpha = 0;
mySplat.scaleX = 0;
mySplat.scaleY = 0;
mySplat.x = (randRange(0,stage.stageHeight+100));
mySplat.y = (randRange(0,stage.stageWidth+100));
Sketch_mc.addChild(mySplat);
mySplat.name = "liveSplat"+i;
trace(mySplat);
Tweener.addTween(mySplat, {alpha:1, _scale:1, /*x:randRange(0,stage.stageWidth-(mySprite.width/2)), y:randRange(0,stage.stageHeight-(mySprite.height/2)),*/ time:randRange(0,5), delay:i*0.25, transition:"easeOutSine"});
}
 
 
}
 
//calls the contstructor to make the circles
kulerCreatorLive();
 
// move prompts and buttons over top of the generated circles...
// AS3 version of swapdepths
var topPosition:uint = this.numChildren - 1;
this.setChildIndex(title_txt, topPosition);
this.setChildIndex(uiPanel, topPosition);
this.setChildIndex(deleteButton_mc, topPosition);
this.setChildIndex(saveImageButton_mc, topPosition);
this.setChildIndex(url_txt, topPosition);
 
function deleteKuler(argument) {
//trace(numCirclesToGen);
for (var i:Number=0; i<numCirclesToGen; i++) {
trace(i);
var tempClip:MovieClip = this;
 
title_txt.visible = false;
url_txt.visible = false;
deleteButton_mc.visible = false;
 
Tweener.addTween(tempClip.box, {_color:"0x000000", time:1});
 
Tweener.addTween(Sketch_mc.getChildByName("liveDot"+i), {_scale:1, alpha:0, time:tempClip.randRange(1,3), delay:i*0.1, onComplete:function() {Sketch_mc.removeChild(this)}});
Tweener.addTween(Sketch_mc.getChildByName("liveSplat"+i), {_scale:1, alpha:0, time:tempClip.randRange(1,3), delay:i*0.1, onComplete:function() { Sketch_mc.removeChild(this)}});
stage.displayState = "normal";
play();
}
 
//trace("Creating kuler");
}
 
 
function showKulerNav(argument) {
deleteButton_mc.visible = true;
saveImageButton_mc.visible = true;
}
 
function hideKulerNav(argument) {
deleteButton_mc.visible = false;
saveImageButton_mc.visible = false;
}
 
uiPanel.addEventListener(MouseEvent.MOUSE_OVER, showKulerNav);
uiPanel.addEventListener(MouseEvent.ROLL_OUT, hideKulerNav);
deleteButton_mc.addEventListener(MouseEvent.MOUSE_OVER, showKulerNav);
deleteButton_mc.addEventListener(MouseEvent.MOUSE_OUT, hideKulerNav);
saveImageButton_mc.addEventListener(MouseEvent.MOUSE_OVER, showKulerNav);
saveImageButton_mc.addEventListener(MouseEvent.MOUSE_OUT, hideKulerNav);
 
deleteButton_mc.addEventListener("click", deleteKuler);
 
saveImageButton_mc.addEventListener("click", saveImage);
 
 
 
function saveImage(argument){
 
var jpgSource:BitmapData = new BitmapData (Sketch_mc.width, Sketch_mc.height);
jpgSource.draw(Sketch_mc);
 
var jpgEncoder:JPGEncoder = new JPGEncoder(90);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
 
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
 
}
 
stop();
 
//UI Panel:
 
 
import caurina.transitions.*;
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
 
//turn off text prompts until they are ready to be used on a successful search
ready.visible = false;
create_mc.visible = false;
submit_mc.visible = true;
input_mc.visible = true;
shape_number_label.visible = false;
bg_color_label.visible = false;
number_shapes_slider.visible = false;
black_rb.visible = false;
white_rb.visible = false;
options_bg_mc.visible = false;
prompt.visible = false;
//create radio button group for background color choosing
var bgcolor_rg:RadioButtonGroup = new RadioButtonGroup("group1");
black_rb.group = bgcolor_rg;
white_rb.group = bgcolor_rg;
submit_mc.addEventListener("click", submitSearch);
 
function submitSearch(argument) {
 
if (input_mc.text != "") {
prompt.text = "Searching Kuler...";
prompt.appendText("\nBe Patient. Art takes time. ;-)");
var kulerURL:String = "http://kuler.adobe.com/kuler/API/rss/search.cfm?searchQuery=tag:" + this.input_mc.text;
var kulerRequest:URLRequest = new URLRequest(kulerURL);
var kulerLoader:URLLoader = new URLLoader();
kulerLoader.load(new URLRequest(kulerURL));
//trace("submitsearch:" + input_mc.text);
 
// Assign listeners for downloading feed
kulerLoader.addEventListener(Event.COMPLETE, feedDownloadedHandler);
kulerLoader.addEventListener(Event.INIT, feedStartedHandler);
 
// Error listeners
kulerLoader.addEventListener(IOErrorEvent.IO_ERROR, feedDownloadError);
kulerLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, feedDownloadError);
 
//
//Feed Event handlers
//
 
//Called when feed retrive begins
function feedStartedHandler(event:Event):void {
trace("Beginning Feed");
}
 
// Called when feed has completely downloaded
function feedDownloadedHandler(event:Event):String {
prompt.text = "No results found, try again.";
// use a try-catch block in case
// xml parsing fails
try {
var tempClip:MovieClip = root as MovieClip;
 
// convert the loaded text into XML
var kulerXML:XML = XML(kulerLoader.data);
 
// if XML succeeded (no error)
// show it in the output window
trace(kulerXML);
 
//add kuler namespace to the app so we can use the custom rss in the service
namespace kulerNS = "http://kuler.adobe.com/kuler/API/rss/";
use namespace kulerNS;
var currentTheme:Object = kulerXML..item[tempClip.randRange(0, kulerXML..item.length())];
//trace("Current Theme is: " + currentTheme);
 
//let the user know there is success by setting text in the prompt.
var currentThemeTitle:String = currentTheme..themeTitle.text();
var currentThemeAuthor:String = currentTheme..themeAuthor.authorLabel.text();
prompt.visible = true;
prompt.text = "Found " + kulerXML.channel.recordCount" results...