TDOT Blog Touchwood Creative

Register | Forgot password?


Touchwood is continuing to grow!

We are looking for talented Flex developers to join our Interactive Group. If you have any interest we would love to meet you. Please email your resume to us at:

jobs@touchwoodcreative.com


Actionscript 3: How to Rotate a Point Around Any Origin

Here's a simple helper function to determine where a point in 2D space ends up after a rotation around a specified origin.


public function rotatePoint(p:Point, o:Point, d:Number):Point{

var np:Point = new Point();
p.x += (0 - o.x);
p.y += (0 - o.y);
np.x = (p.x * Math.cos(d * (Math.PI/180))) - (p.y * Math.sin(d * (Math.PI/180)));
np.y = Math.sin(d * (Math.PI/180)) * p.x + Math.cos(d * (Math.PI/180)) * p.y;
np.x += (0 + o.x);
np.y += (0 + o.y)

return np;

}

 

This function takes the point you want to rotate(p), the origin or point you want to rotate around(o), and the degrees(d) of the rotation. After translating the origin and point to reflect an origin of (0,0), converting the degrees into radians, applying some simple trigonometry, and then moving point back you get the new location of your point.

This function is handy for when you are trying to find a point on a polygon or shape after it has been rotated.

Adobe: Why AIR Applications Currently Cannot Execute Other Applications

Last night I was reading this Adobe forum thread about the pros and cons of AIR applications executing other applications. Product manager Rod Christensen left a post explaining Adobe's reasoning for this limitation. Here are the main points of interest:

"The primary reason that AIR 1.0 does not include support for launching
native applications originates from a founding design
decision/philosophy. Applications that do not depend on other
applications to be installed result in a better user experience. Our
goal with AIR has been to deliver a runtime that delivers applications
consistently across operating systems. Please note that this doesn't
mean we're right nor that we might not change our minds on this."

...............

"As with any design decision, there's plenty of opportunity to debate
the topic and this is something we continue to discuss even internally.
The major disadvantage is that it's much more difficult to take
advantage of existing code libraries or launch other native"
applications. "

"At the same time, one advantage to the current
design is that when you distribute an application, you do not need to
say, 'This is a really great application, but make sure you have
Microsoft Windows (or OSX) installed as well as Microsoft Word (or
Photoshop or some other native product) to really take advantage of
this application.''

Actionscript/Flex: How to Programmatically Add a Link to a LinkBar

Problem:

You have a LinkBar's dataprovider bound to a viewstack, but you want to add an extra button that opens an URL in a new browser window when clicked.

Solution:

Flex: Is it right for you?

I was cruising the FlashKit forums and came across the following post:

Hi All out there,

Im new to flex. I'm thrilled with the HYPE flex has caused, and the
heap of awards in so little span. I'm a flash designer and programmer.
I know a little bit of web designing, i usually use Dreamweaver. Im not
so good at PHP, and other web based scripts. I'm fimiliar with
Macromedia Flash 8 Professional. I wanna know some thing from my GURU's
here.......
1. Is flex for me?
2. Is flex a complete RIA or can desktop exe's be created?
3. Does Flex 2 have support on OS 10.4.9 and 10.5 Leopard? Can i use a
single downloaded copy for both or will i need a MAC copy for MAC?
4. Im presently into desktop based applications in flash, so question 2 repeats.
5. Can I get the names of some fine, easy learning books on flex?
6. What's the future of Flex over Flash?
7. Does Flex support writing files to HD, OS native popup's, CD
functionalities, Printing functionalities, Audio and Video
functionalities, text parsing functionalities?
8. I have some fla and swf files with me, I want to add flex database
functionalities. Can i import the swf? or fla? and code the buttons on
my swf in flex?

9. You look tired. i will be back with more queries.


Im very keen to know about flex. I have read many articles. I hope
someone could answer me my questions and get me started with flex.

Regards
Roshan Kolar

 

I think Roshan is a like of a lot of people wondering if they should continue using Flash or should commit to adopting Flex as their development platform of choice. To help, I thought I would share my opinion after working with Flex for the past year...

Actionscript 3: How to use describeType() to Save an Object to XML

Needed Resources:

Final Product:
A base data holder class that will have a toXMLString() method and a parseXML() method to give its descendants the ability to generate a XML string or to instantiate themselves with a XML string.

Execution:

  1. After creating the class file
    and constructor, create the toXMLString method:


public function toXMLString():String{

Why addChild May Not Work With Sprites in Flex/Actionscript 3

This post is in reference to AxiomFlash's message board post at FlashKit. AxiomFlash cannot get the following code to work in his class that extends the main Application class:


private function init(eventObj:FlexEvent):void
{

trace("init()");
var clip:Sprite = new Sprite();
clip.x = 100;
clip.y = 50;
clip.graphics.beginFill(0x00aa00, .7);
clip.graphics.drawRect(0, 0, 300, 200);
addChild(clip);

}

 

When this application is executed the following error message appears:


TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Sprite@4abb3c1 to mx.core.IUIComponent.

Rails: Using Partials to Render XML

With Ruby on Rails there is a bit of a trick to getting partials to work when rendering XML. Partials are a key part of DRY and using them saves you time and energy when rendering HTML or XML. They are easy enough to use when rendering XML, there is just a simple pattern to follow to get partials working when rendering XML.

How to Read a Directory's Contents with Flex and AIR

Needed Resources:

Final Product:

A small application that traces out the contents of the user's documents directory. This was originally a posting for help by Boombanguk in the FlashKit message boards.

How to Read and Write XML files with Flex and AIR

Needed Resources:

Final Product:

An AIR application with a load xml and save xml button. The load button prompts the user to find an xml file titled "person.xml." Once the user has selected the file, the first name and last name of the person will be displayed in two text inputs. The user can then edit these entries and save them back to the file using the save button.

Stay DRY (Don't Repeat Yourself): Audio AS3 Helper Class

What this is:

A commented Actionscript 3 class that is a static helper class that allows a developer to load/unload, play, pause, and skip to a point in an audio track. With this, a developer can separate out the redundant tedious code necessary to play an audio track from the view/UI code.

A break down of the methods:

  • AudioManager.loadSong(url)
    Use this method to load in your audio track.

  • AudioManager.playSong()
    Plays the currently loaded track.

  • AudioManager.skipToPos(n)
    Skips to a location in the track (in milliseconds.)

  • AudioManager.pauseSong()
    Pauses the current track.

  • AudioManager.setVolume(n)
    Sets the volume level of the current track (0-100.)

  • AudioManager.getVolume()
    Returns the current volume level of the track (0-100).

  • AudioManager.getSongLength()
    Returns the length of the current track in milliseconds.

  • AudioManager.getSongPos()
    Returns the current position of the current track in milliseconds.
Syndicate content
© Touchwood Creative 2007 | We use Firefox