Some favorite site feeds aggregated locally: iPhone Development RSS   Adobe Labs RSS   Macrumors RSS

Tuesday, February 17, 2009

Beanstalk just upgraded free accounts

Tuesday, February 17, 2009    0 Comments

I just received a welcome email.
This is an update for all Beanstalk account owners who are currently on the FREE plan. Today we upgraded storage on all free accounts from 20mb to 100mb.
That's super sweet. I like this SVN service quite a bit, if you haven't tried it I suggest you do. Beanstalk Twitter.

Labels: ,

 

Friday, February 13, 2009

Namespaces are a pain

Friday, February 13, 2009    1 Comments

var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener( Event.COMPLETE, onLoadXML );
myLoader.load( new URLRequest( "http://www.xignite.com/xquotes.asmx/GetQuote?Symbol=AAPL" ));
function onLoadXML( e:Event ):void
{
var ns:Namespace = new Namespace("http://www.xignite.com/services/");
var myXML:XML = new XML( e.target.data );

trace( "Name " + myXML.ns::Name );
trace( "Last " + myXML.ns::Quote.ns::Last );
trace( "Price Earnings " + myXML.ns::Statistics.ns::Price_Earnings );
trace( myXML.ns::News.ns::StockNews.ns::Headline[0] );
var len:Number = myXML.ns::News.ns::StockNews.ns::Headline.length();
trace( myXML.ns::News.ns::StockNews.ns::Headline[len-1]);
}
I mean, come on, that's just weird. Why couldn't I set the namespace once somehow and just use regular dot notation from then on out? (Unless I can and I am missing something). I pulled the code above out of my backside and lo' and behold it worked.

Namespaces are something I need to properly wrap my head around, as it seems it's coming up more and more. I wasn't even quite sure that my original parsing problem was namespace related or not. In the above XML returned, do they really need to define namespaces?

Here is something better (this is all still a bit of a pain):
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener( Event.COMPLETE, onLoadXML );
myLoader.load( new URLRequest("http://www.xignite.com/xquotes.asmx/GetQuote?Symbol=AAPL" ));
myLoader.dataFormat = "XML";

function onLoadXML( e:Event ):void {
var myXML:XML = new XML(e.target.data);
if( myXML.namespace() != null)
default xml namespace = myXML.namespace();
trace("Outcome: ", myXML.Outcome);
trace("Delay: ", myXML.Delay);
}

Labels: , ,

 

Monday, February 9, 2009

Navigating Yahoo! weather nodes

Monday, February 9, 2009    1 Comments

I took a straight XML approach to loading weather data from Yahoo! by simply using a URLLoader and using the address http://weather.yahooapis.com/forecastrss?p=01701. It returns an XML blob full of current and forecast data, which is great & it's very fast. Previously I was using a different service and it worked well for the 10% of the uptime the service provided (ugh). So a service on stronger footing was required, hence Yahoo!

Accessing the nodes by hand isn't exactly straight-forward though. One of the nodes I am most interested in looks like this in the resulting XML: <yweather:condition text="Mostly Cloudy" code="26" temp="57" ></yweather:condition> - perfectly understandable. But if you try to access it like so:
private function loadedXML(e:Event):void
{
var myXML:XML = new XML(e.target.data);
trace(myXML.channel.item.yweather:condition);
}
you'll get a compiler barf about that ":" in the node name. So you CAN access it like so:
private function loadedXML(e:Event):void
{
var myXML:XML = new XML(e.target.data);
trace(myXML.channel.item.children()[5]);
}
However that leaves an incredibly bad taste in my mouth as if the order of the tags ever change, this code breaks. I did throw a question to the FlashCoders list about this too. There has got to be a superior solution to this. I did quickly try to use the Yahoo! webapis classes to get this job done, but I was getting strange WeatherResultEvent errors and decided to quickly roll my own up.

UPDATE:

Thanks to FC, I looked to Namespaces. It took a bit to get it going, but here we are:
private function loadedXML(e:Event):void
{
var myXML:XML = new XML(e.target.data);
var foo:Namespace = new Namespace("http://xml.weather.yahoo.com/ns/rss/1.0");
trace( myXML.foo::condition.@text );
}
A major part of the problem was the online specifications from Yahoo! were wrong, and the namespace URI was incorrect. That didn't help much. Once I dug into the returned XML myself, I saw the problem right away.

UPDATE 2:

Here is something I wasn't aware that I could do. Now, there are several yweather:forecast nodes, one node per day reported. Well, you could grab the node attribute, which runs all the node values for each into one big, useless string that you can't substring because you don't know the length of each individual one, or you can do this:
var txt:String = myXML.channel.item.foo::forecast.@text[0];
var txt2:String = myXML.channel.item.foo::forecast.@text[1];
Works like a charm and you don't need to approach any hacks getting that data out of there. I tried it on a whim & it worked, albeit I am not completely up to snuff with XML as I was with AS2. AS3 is SO much better as I find out nearly daily. I don't think they need AS4 ever... just add some things to 3.

Labels: , ,

 

Thursday, July 31, 2008

Sample MXML

Thursday, July 31, 2008    0 Comments

Testing MXML support. Found this @ Shigeru Nakagaki (part of a post: AIR:How to use RemoteObject without compiler option.)
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication layout="vertical"
xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="init()">

<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;

private function init():void
{
//
}

private function resultHandler(e:ResultEvent):void
{
log.text = e.result.toString() + "\n" + log.text;
}

private function faultHandler(e:FaultEvent):void
{
Alert.show(e.fault.message);
}

private function sendMessage():void
{
// call CFC method with arguments
ro.echo(msg.text);

msg.text = "";
}

]]>
</mx:Script>

<mx:RemoteObject id="ro"
destination="ColdFusion"
endpoint="http://127.0.0.1/flex2gateway/"
source="AirRemoting.BlazeDSCFCTest3"
result="resultHandler(event)"
fault="faultHandler(event)" />

<mx:HBox>
<mx:TextInput id="msg" />
<mx:Button label="send" click="sendMessage()" />
</mx:HBox>

<mx:TextArea id="log" width="200" height="200" />


</mx:WindowedApplication>

Labels: ,

 

Wednesday, June 11, 2008

Number.fromCharCode

Wednesday, June 11, 2008    0 Comments

We've all been acquainted with String.fromCharCode in relationship to event.keyCode, but it also works with Number. Why would you want to do that?

Well, I am getting sets of keyboard inputs as keyCodes from a piece of hardware, and I build up an angle to use. A delimiter lets me know when to stop per each set.

In order to translate the keyCodes back to numbers for use in building up the angle to use, instead of using a method to translate the keyCodes to a Number to use, you can simply do something like this:

var code:Number = event.keyCode;
var n:Number = Number.fromCharCode( code );

And from this I build up an array, looking for a delimiter all the time, and when I get the delimiter, build the angle number and use it. Of course this fails if you are getting keyCodes that are out of range of 0-9, so you need to filter your keyCodes as they come in.

I haven't seen any public code (yet) that uses Number.fromCharCode yet, and for me it works perfectly, so I thought I'd throw this out there.

Labels: ,

 

Friday, July 6, 2007

Test Code Posting

Friday, July 6, 2007    0 Comments

I am testing the display of some code, since I am migrating CSS and other things, I'd like to try to ensure a sweet transition when the DNS changes take place. This is just a piece of larger code stuff.

package
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

// XML-Specific
import flash.events.ErrorEvent;
import flash.xml.XMLDocument;
import flash.net.URLLoader;
import flash.net.URLRequest;

/**
* AS3.0 Class to provide user selection of various
* Flash-specific resource documentation/files.
*
* Author: Eric E. Dolecki
* Copyright: 2007, Eric E. Dolecki
*/
public class Resources extends Sprite
{
private var BaseColor:Number = 0x414042;
private var RollOverColor:Number = 0xCCC2C0;
private var SelectedColor:Number = 0xF15B40;
private var navArray;
private var nCurrentSelection:Number = 0;
public var sectionId = "";

// XML-Specific
private var urlLoader:URLLoader;
public static var data:XML;

public function Resources()
{
navArray = new Array();
xmlLoader();
};
}
}

Labels: ,