Tag: AS3

Simple tip #3 – Utility SWC (library project)

Simple tip #3 – Utility SWC (library project)

Do you frequently use simple actionscript functions in more than one project. Perhaps you’ve got a function to do tracking, parse strings to dates, or return a random colour etc.

I’m sure most folk will have struggled to think of what project they last used a generic function ABC in as they could do with using it for project XYZ and would rather spend 30 mins searching for said function rather than rewrite it.

Well as explained below is a way to stop this from happening and hopefully save you a heap of time.

  • Step 1

    – Create a library project.

  • So using flexbuilder, go to File->New->Flex Library Project.
  • This will create an empty library project.
  • Step 2

    – add in your Utilty class to the library project.

  • To do this add/create a Utility actionscript file that contains your static functions. Save, and this should then automaticlaly create a SWC file inside the library bin folder. (If it hasn’t and the file added has no errors then check the project properties to make sure the newly added file is being included – see pic)

  • Step 3

    – add the reference of the newly created SWC file to any project you intend to use it in.

  • So go to your project you wish to use the SWC with, then select the projects properties and inside ‘Flex build path’ select ‘Add SWC’.
  • Browse to the the previous library project and select the SWC from its bin folder.

You are now done, any time you update the code in the library project, those changes will be reflected in any project that references the SWC file automatically.

Previous Tip

Next Tip

[ad name=”ad-1″]

Zooming Example

Zooming Example

Ages ago I worked on an accessibility tool that followed the mouse around the stage and magnified whatever the mouse was over. It never made it to the final stages of completion but after reading a question on flexcoders for a zooming tool, I thought I’d revisit the idea and create a simple magnification/zoom example.

Before

During

After

 

Right click the example for source code.

This isn’t for production, just a POC on how to do enlarging, enjoy.

[ad]

LocalConnection – AIR -> Flex (and back if you want)

LocalConnection – AIR -> Flex (and back if you want)

One of the long standing flex projects I’ve been working on is a tool for showing of various funds and fund videos with related PDF’s and graphs etc.  This is updated relatively frequently and due to various restrictions it’s not as straight forward to test updates as the client would like.

So what would be a good way to test a live flex app (which is static) that loads dynamic data. Well the idea was to create an AIR application that would be a visual editor for the data that would then send that data using LocalConnection, this would update the model in the live flex app and the new data would be displayed so that it could be checked.  All of this would be local to the clients machine as by using the localConnection you’re only changing the local data model and not the data on the server.

Sounds very straight forward, but getting it just right took a little while.

Here’s the basic on how. (open demo windows, run both apps and right click for source to get more detail)

AIR application

Flex application

1)    Create an AIR app that sets up a localconnection

2)    Create a byteArray of whatever you wish to send (I’m sending just text, but there is no reason why you couldn’t say send an image or similar)

3)    Split byteArray into chunks of under 40K and then send them across using localConnection

4)    At the same time create a flex application with a localConnection

5)    Let it allow the domain your message is coming from (start with * for testing if not sure, just make sure you don’t leave * in for any live version)

6)    Create a handler function that matches the name of localConnection send parameter that you set up in the AIR app

7)    Join the 40K chucks of data if necessary then do what you like with them.

That’s it, message received over and out :).  check out the source code for more details.

[ad name=”ad-1″]