Flex Community Blog

Singleton Event Controller

[edit: the links referenced in this post are unfortunately broken, I have removed them and posted the full code - see below.]

I haven’t posted in a while. I’ve been involved in a big project, so will have lots to post soon. But I found a nice tidbit to share. This comes from this site:http://www.angryrocket.com/?p=113 – the link is broken – the code can be found below.

this is a great class to centralize and organize project-wide events, that any class in the project can access.

The real need for it for me came when I had a custom scroller object (the scroll bars in flex suck), that needed to see keyboard events. I wanted the keyboards events to be dispatched from the stage, and not targeted to specific instances of the scroller, as there were many. As I understand it, events dispatched from the stage do not really have a capture or bubble phase, and won’t nicely propagate up the display list, the same way they would go “down” the display list to the stage, if they were dispatched from the scroller (which they could not be in this case). So I had the stage listen for the keyboward event, and when it heard it, dispatch it through this singlton instance, whcih the scroller can invoke as a listener, and viola, it worked perfectly! All events that need to travel all over the project, to parents, grandparents, and to all points in the display list, will now do so through this great EventCentral singleton.

here’s the code:
Read More…

Post to Twitter Tweet This Post

Read files from a folder and create xml file with php

I recently did this for a flash mp3 player (I’ll write on that later), but it would work just fine for an xml photo gallery like the one shown here

Basically what I was doing was creating quite a few mp3players, each with many songs, and didn’t want to edit all the xml files, as the player I was using reads from an xml file with the following structure:

< ?xml version="1.0" encoding="UTF-8" ?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<tracklist>

<track>
<annotation>1. Song Title 1</annotation>
<location>http://www.path_to_your/song 1.mp3</location><location>
</location></track>
</tracklist>
</playlist>

So what I did was this:
Read More…

Post to Twitter Tweet This Post

(more) text effects with TweenMax

EXAMPLE

This is an improvement on the technique used here

This one deals with linemetrics, and solves the weakness of the other one (that it only works well with monotype fonts)

Here’s the class code:

Note – you must have the tweenMax library in your library path

Read More…

Post to Twitter Tweet This Post

Auto Resizing Text Area Component – Flex

Just to spread the word, there is a great article here with an AutoResizing TextArea component that seems to work well. I added one small thing to support resizing of htmlText too (see below).

(add this code to the component)

override public function set htmlText(value:String):void
{
// calling super method
super.htmlText = value;
// if is auto resizable we call
// the resize method
if (_autoResizable)
resizeTextArea();
}

Also, as a side note: you can bind to the height of the text component to resize containers etc. like this:
Read More…

Post to Twitter Tweet This Post

cool xml photo gallery with flex and PaperVision3D

This is an example of a photo gallery in Flex using papervision3D and a “sliced cube” effect for the transitions. The image data is loaded from an external xml file.

Major credit goes to John Lindquist for the cool effect. Read his article here:

http://pv3d.org/2009/04/09/sliced-cube/

john says: “I’m sorry the code is a big pile of crap. I’m too lazy right now to clean it up”

well, I just made it worse! :)

Here’s my example (right click for source)

http://blog.flexcommunity.net/lab/ppv3dGallery_slicedCube/

Here’s a description of what I did:
Read More…

Post to Twitter Tweet This Post

relative paths, HTML and embedded swfs

I recently had a need to load external jpgs into multiple swfs, which were embedded into an HTML page. The swfs were in sub-directories. The problem soon arose was this:

Referencing relative paths from an swf that is not in the root folder (the same folder containing the HTML page) doesn’t work. For example, if you have

root -> html page -> swf folder -> image.jpg

And in the swf file you try to load “image.jpg” as a relative path, it does not work. According to the swf (embedded in the HTML page), the jpg it is looking for should be located in root -> image.jpg

It is not there. it is actually in root -> swf folder -> image.jpg

I found others on blogs and forums with the same problem
Read More…

Post to Twitter Tweet This Post

Documenting your classes with ASDoc

I started working on this today for the first time for a new project I want to document. After some reading online, I found many people having problems with this, and complaining about problems using ASDocs through the command line, lack of documentation (which is kind of ironic), and many people saying they’ve spend hours and days trying to get it to work. I decided to skip the command line and try to run ASDOcs from Flex Builder. I’m happy to report I’ve gotten it to work after about 20 min, with the help of this great article:
Read More…

Post to Twitter Tweet This Post

Using Flex swf to load html into frames

I recently had a reason to do this, and saw that many people online are having problems. Here’s a solution, and a few notes to help. First the Flex code:
Read More…

Post to Twitter Tweet This Post

GuerrillaMail disposable email

This isn’t about Flex or Flash, but it’s a useful item for any developer, and I’d thought I’d share to anyone who doesn’t already know about it. Using Guerrilla Mail, you can generate a free, anonymous, disposable email address that expires in 1 hr. You can use this address to sign up to things that require an email (and send a confirmation code/link) that you plan to only use or sign up to once.

It works like a charm.

Cheers

http://www.guerrillamail.com/

Post to Twitter Tweet This Post

Tracking ‘Pages’ in a Flex app with Google Analytics

Tracking ‘Pages’ in a Flex app with Google Analytics

Google Code Page:

http://code.google.com/apis/analytics/docs/tracking/flashTrackingIntro.html

download the tracking library here:

http://code.google.com/p/gaforflash/downloads/list

1)After downloading the zip file, unzip it, and goto lib/analytics.swc (not analytics_flash.swc)
2)in your flex app, goto project -> properties -> Library Path -> add swc, then add the analytics .swc to your build path

make sure to add the namespace to the application (add the following within the mx:Application tag:

xmlns:goog=”com.google.analytics.components.*”

Then you can implement tracking in the following way:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:goog="com.google.analytics.components.*" layout="vertical" creationComplete="trackInitialView()">
<mx:Script>
<![CDATA[
public function trackInitialView():void{
tracker.debug.minimizedOnStart = true;
tracker.trackPageview("HOME");
}
]]>
</mx:Script>

<goog:FlexTracker id="tracker" account="your_account_number" visualDebug="false" mode="AS3"/><mx:LinkBar id="myLinkBar" right="15" dataProvider="myViewStack" itemClick="tracker.trackPageview(myViewStack.selectedChild.label.toString());" />

<mx:ViewStack id="myViewStack" width="500" height="500">
<mx:Canvas label="HOME" backgroundColor="#ff0000"/>
<mx:Canvas label="ABOUT US" backgroundColor="#00ff00"/>
<mx:Canvas label="CONTACT" backgroundColor="#0000ff"/>
</mx:ViewStack>

</mx:Application>

As you can see from the example, you can track things besides pageviews, and in fact any event you can think of (like the end of a video) can be tracked. See the above links for more information.

Connect with other Flex developers here: http://connect.flexcommunity.net/

Post to Twitter Tweet This Post