Tuesday, May 3, 2011

Parsing Params from a UI in PHP

I've seen a lot of this out there, and seen a variety of scripts that...well...just don't work. People recommend plugins, frameworks, all that, just for the simple task of some basic params parsing.

To be frank, as I go on using Zend framework, I find it hard to believe the amount of effort people will put into searching for pre-made solutions for things that are really pretty simple. I suspect this has to do with the fact that "framework" is misinterpreted as "does everything for you", which leads a lot of what I call "script hackers" to pursue them, when in fact using frameworks is a more advanced programming undertaking that, imho, separates the men from the boys, as it were. I understand that situationally a lot of that might be useful, but for me, when it comes to basic operations such as this, I prefer to use the features of the language without additional bolt-on libs, mods, and what have you.

Here's the code I use, which has worked consistently well, in a little util class. If you have other character or encoding concerns, just bolt them into the processing before you hit the foreach loop.



public static function parseURIParams ( $uri )
{
$params = parse_url ( $uri, PHP_URL_QUERY );
$values = explode ( '&', $params );
$finalParamsArray = array ( );

foreach ( $values as $str )
{
$keyVal = explode ( '=', $str );
$finalParamsArray [ $keyVal [ 0 ] ] = $keyVal [ 1 ];
}

return $finalParamsArray;
}

Tuesday, September 7, 2010

DataGrid Reminder: Item Renderers Don't Trigger Events Until They're Visible

Ran into this recently; no code, since that's not really necessary. But this info is pretty valuable imho. I've seen tons of info on the net in all the forums that work around this every which way without every actually stating the precise issue.

Say you've set up the following:

- A datagrid with a dataprovider (say, XML).
- One of the columns in the datagrid has a custom renderer.
- You need to update a model (say, processed XML you will send to a service after the user is done with the grid) with some data that is automatically populated in that renderer's UI field (like a default value).

For instance, say you have this:

<item>
<itemdata>Hello</itemdata>
</item>

You use this as your dataprovider. Your custom renderer has a textfield. You write Hello into the textfield on dataChange. Nice nice so far.

Now, when that textfield changes, you want to update a model of XML, or trigger some other event, whatever. You add the textfields change handler, you see it work, you breakpoint the code that updates the model, and you see the info added. Nice.

Then you say, "let me blow it out to 20 rows". You add them all, you breakpoint the model code, and it works...up to a point. For some reason, 7 or so of the pieces of data you want in the model are there, but then it just stops, as if the data is getting skipped or just not sent.

You fiddle with it...sometimes 7, sometimes, 5, sometimes all 10. WTF is going on?

If you know the answer already, raise your hand...but I bet you don't (I looked and asked around for a week before figuring it out).

Drum roll...

...datagrids only render visible rows. If you had to scroll to see any of your rows, then those renderer's events never fired (like it's textfield change event). Which means that the events never dispatch, so your model, or whatever, never gets the message.

So, if you're counting on events from a renderer events to update a model or trigger some other action when all the data is initially loaded into the datagrid based on a value set in a renderer, don't dispatch the events from the renderers, because if they aren't visible, they'll never send their messages.

Perhaps a datagrid creationPolicy of "all" would be useful under certain circumstances.

As always, thanks for visiting.

Friday, May 21, 2010

Passing Simple QueryString Data from SWF to SWF using SWFLoader

Lot of posts out there with people trying to get around this one. It's a pain; under certain (most) conditions, if you try to simply load a swf into a swfLoader, and pass parameters by appending the path to the swf, when you test the parameters in the loaded swf, you get nada.

Ugh.

Easy workaround; use this in the LOADED swf (so in the code of the swf you loaded):

Application.application.loaderInfo.loaderURL

That reveals the entire path the loader of that swf used. After that, parse out your values and off you go. Not as nice as if they appeared as neatly packaged object properties, but it works, and parsing a querystring is 101 stuff anyway.

Easy one, but effective.

As always, thanks for visiting.

Tuesday, April 13, 2010

Adobe CS5 iPhone building is "*Subject to Apple's current requirements and approval."

If you read my last post, you know that Apple altered their licensing agreement for applications. Not only is apple telling you how you can distribute them, but now they are telling you how you can build them.

Here's the meat of the matter:

"3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited)."

It's corporate control at it's worst. Apple has surpassed Microsoft in terms of "evil empire". Microsoft may be berserk with their licensing pricing and enforcement, but one thing is true, they NEVER told me that I couldn't use my computer whatever way I wanted as far as a developer. As long as the binary output runs, I can install it, for FREE. Apple, however, has decided that's not enough money or control. Now they want to specify the language you write in, how it should be compiled, and all the rest of it, AND get a fee JUST so you can put an app on an iPhone, iPod Touch, or iPad. The more I look at it, the more I see corporate, hysterical paranoia. Apple simply wants to own and control all content distribution on the web.

Apple = Open Web? No, they do not. They = closed devices supporting the technologies they choose, the way they specify. They are doing evil; they could learn a lot from Google.

What evil?

The change has affected numerous small development shops that were counting on Adobe's Release of Flash CS5, as well as shops working on compilers for various dev technologies. Apple is taking every step they can to keep anything other than Apple licensed developers, and Apple licensed tools, out of the realm of Apple mobile development, in particular, the petulant snubbing of Adobe's Flash. They offer all kinds of weak, easily repudiated reasons for not allowing the technology to be installed in their Safari browser on the iPad and the iPhone, or as a runtime that can support Air apps. I won't rehash these, other than to say, if a $250 netbook can run Flash and Air, then there's no reason in the universe that the iPad shouldn't be able to, unless all it really comes down to is that the iPad is a glorified iPod Touch without the camera. I mean...no USB port...no Flash...no multitasking yet...come on. Has Apple forgotten that technology isn't just about designing cool looking things?

Anyway, Adobe has added this little quip to the pre-release announcement of the CS5 Master Suite, due for release in mid-May:

"Publish content virtually anywhere, using Adobe AIR® for desktop applications and mobile platforms including the iPhone®*, or Adobe Flash Player for browser-based experiences.
*Subject to Apple's current requirements and approval."

Notice that last line. This means that, Adobe may give you a tool that can build iPhone apps from Flash/ActionScript...but you may never be able to use it. All Apple has to do is keep modifying the license agreement to shut Adobe out forever, and as they clearly show by the new 3.3.1 paragraph, they're more than willing to do it.

For shame Apple. You're supposed to enfranchise developers, let us create tools to work with your platform. But instead, you react by putting more mortar on the walls around your mobile platform, paid for by developers that just want to put an app on an iPad.

HP Slate for me (google it), and depending on how Android 2 goes over the remainder of my iPhone contract, it's a distinct possibility I'll abandon Apple's mobile platform altogether. My whole perception of what I see when I look at my iPhone has changed, and I don't like it. Sure, this may only matter to developers, but developers build the apps you love. Historically, where the developer goes, the consumer follows. If Apple keeps heading this way, it's just a matter of time until people start jumping ship.

Is this all written in stone? Hard to say. But it is indeed written, at least for now.

Friday, April 9, 2010

Apple tightens control over development...again.

Take a look at this: Before today, the Apple License Agreement for apps read like this:

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.

As of today, it looks like this:

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).

Now, I don't think this necessarily means the Flash CS5 is torched (if you didn't know Flash CS5 has the ability to compile ActionScript apps to run on iPhone). The only thing it MUST do is, it must appear to the external eye that the app was written in C (objective, C++, etc.). If there is a compiled binary that speaks to the iPhone API through an intermediary layer, it's out of license.

Whatever the case, this is going too far. Not only does Apple want to specify how you can distribute your apps, they want to tell you exactly how to write and compile them. I'm reasonably confident this won't stop Adobe, as they wouldn't have gone this far without understanding Apple's probable reaction to their iPhone compiling tools, but it will certainly torch a number of efforts underway to get iPhone dev into general development, like Java, etc; I know for sure the .Net->to->iPhone effort is now out of license, as it uses an intermediary layer (or did anyway).

C'mon Apple. You've got your distro lock, for pete's sake if home engineers can come up with another way to put it on wax, and it passes your already existing restrictions, back the hell off.

Friday, March 19, 2010

Text Layout framework for Flash/Flex (Player 10)

Like many of you I'm sure, I've struggled with text in Flash/Flex more than once. For the most part, I've learned to get it to do what I want, but, there's still some things missing, especially when it comes to allowing users to manipulate text, an easy way to integrate robust HTML text for formatting, that sort of thing.

I haven't played around with it enough to write anything useful, but this looks very promising:

http://labs.adobe.com/technologies/textlayout/

The gist is, the text framework is getting a complete overhaul; we'll have it Gumbo, and it's already in CS4, all targeted at Player 10 (which is a significant evolution, what with the ability to save files locally and such as well).

Summary of highlighted features, this is interesting stuff:

- Bidirectional text, vertical text and over 30 writing systems including Arabic, Hebrew, Chinese, Japanese, Korean, Thai, Lao, the major writing systems of India, and others
- Selection, editing and flowing text across multiple columns and linked containers, and around inline images
- Vertical text, Tate-Chu-Yoko (horizontal within vertical text) and justifier for East Asian typography
- Rich typographical controls, including kerning, ligatures, typographic case, digit case, digit width and discretionary hyphens
- Cut, copy, paste, undo and standard keyboard and mouse gestures for editing
- Rich developer APIs to manipulate text content, layout, markup and create custom text components.

Interesting stuff.

Thursday, March 11, 2010

March Edition of Flash Flex Dev Mag is out.

The March Edition of this mag is available now, with my article, "Dynamic Views and Mediators in PureMVC".

Check it out at:

http://ffdmag.com/download-2-2010