Archive for category ACTIONSCRIPT 3.0

Create a png with php and as3

For a project I was on awhile ago, I needed to decorate a character with different items of clothing. When the user was done ‘dressing’ their character, they would press a button and the whole character would shrink down so it would fit as an ornament on a tree. In order to not confuse the issue, I am going to only show the code that enables you to take a movieclip and create a png from it. In order to do this, you will need to include the Flex SDK as a part of your flash build (for the Base64Encoder class) and you need to download as3corelib. To include the Flex SDK, in your Flash preferences add this line: (Mac OSX)

//VERSION will prob be 3.5, 4 etc...
/Applications/Adobe Flash Builder 4/sdks/flex_sdk_VERSION/frameworks/projects/framework/src

Code after the jump…

  CreatePNG (44.4 KiB, 30 hits)

Read the rest of this entry »

,

No Comments

Cast XMLNode to Boolean – AS3

I was having a bit of difficulty making an xml node that had a value of true/false be cast properly as a Boolean. Turns out a good method is to when you are setting it, test it against a string value of true. The boolean will only be set to true if the string in your XML file is “true”.

1
2
//Example
var myBoolean:Boolean = XML.isTrueFalse == "true";

2 Comments

Avoid Twitter API-IP Call Limit

Twitter limits the amount of calls you can make to its API and from one IP to a few hundred an hour. So that means if you have something on the page that is showing your latest tweets, it will only work for the first few hundred people. We have a really high traffic site and needed a more robust solution.

What we did is create a php file that loads the XML from the twitter user timeline (example) and saves it on our server. We setup a chron job to call it every minute. The Flash movie loads the XML file that our php file creates for us ensuring that we will never go over the limit but always have the most up to date content from Twitter displayed on our website.

If you have any questions or want an example of the source, post in the comments. Running Example.

Resources Used:

  • The LoadXML and LoadURL files from here.
  • The AxisScroller from here.
  • Tweenlite
  • , , ,

    No Comments

    Convert links in text to clickable links in Flash AS3

    I found this on StackOverflow but it took quite a bit of searching to find. Here you go:

    1
    
    title_str = title_str.replace(/((https?|ftp|telnet|file):((\/\/)|(\\\\))+[\w\d:#@%\/;$()~_?\+-=\\\.&]*)/g, "<u><a href='$1'>$1</a></u>");

    ,

    No Comments

    Dynamically Add UIScrollbar to Textfield AS3

    This is building off my previous post and adding a scrollbar to the textfield if there are too may tweets to fit in it. You don’t need to load data from a HTTPService but this is helpful for loading data when you don’t know its length ahead of time.

    Read the rest of this entry »

    , , ,

    No Comments

    Drop Down Menu with AS3

    Here is a code snippet that I have been using to create dropdown menus from movieclips in actionscript 3. I probably should try to wrap this up in a class as I bust out this snippet whenever I need this functionality. Usually when I have a ‘button’ that I need to have open up a larger movieclip with selectable/dynamic information in it. Would be nice to set a moviclip to be the ‘menu trigger’ (in the example: _sMouseOver) and another to be ‘the target’ (in the example: _sMenu) in a class… Maybe I will work on a class implementation later.

      AS3 Mouse Over Menu (15.4 KiB, 216 hits)

    Code Snippet after the jump: Read the rest of this entry »

    ,

    No Comments

    AS3 – Snow Effect

    The best snow script that I have seen thus far. You get great performance even with 1500 different snowflakes in the movie and practically everything is customizable. I will definitely be using this in projects that require a snow affect.

    What you can customize:

  • side the snow blows in from
  • number of flakes
  • size of flakes
  • distance from camera (range)
  • snow alpha
  • wind force
  • time between wind force changes
  • gravity (b/c who doesnt want 0 gravity snow)
  • Check it out: Tim Soret – Snow

    , ,

    1 Comment

    AS3 – Load XML Document Class Example

    One thing that I do quite often in Flash is load XML. In order to save time, I separated a lot of that code out into external class files. I also created a snippet of code that calls those files in order to save time when I want to use them. (You will need Lee Brimlow’s snippets panel for this to work.)

    The LoadXML and LoadURL classes are probably very similar to those found at Learning Actionscript 3 as that is where I learned a lot about this topic previously. Hope you find this helpful!

      Load XML files (774.5 KiB, 109 hits)

    Code snippet (for the panel) after the break…

    Read the rest of this entry »

    , , , ,

    1 Comment

    AS3 – Draw Circle Animation Based on Time

    If you need to perform an animation and have it be standard when viewed across different machines, it is best to use an onEnterFrame event. I had a need in a project recently to draw a circle in a specified amount of time. I had been using the Timer class but found major time discrepancies between running the code locally and running the code in a browser. With some code that Jackson Dunstan provided, I was able to modify the animation so that you can start/stop drawing the circle based on user input. (In the sample provided it is by clicking the stage) I hope this helps someone in a similar situation. Code after the jump…

    Read the rest of this entry »

    , , ,

    1 Comment

    AS3 – Loading CSS and Fonts

    Working with CSS and fonts in Flash (especially with dynamic text) can be a huge pain. I have come up with a way that makes it a lot easier. What I do is load them up, store a reference to the css file in a global class, and simply refer to that class when you need to use the fonts and css. The css styles dictate which fonts are used where within your application.

    This method seems to work out well and saves on file size as you are referring to an instance of the font instead of instantiating it over and over again etc. (You will need the FontLoader class in order for this to work.)

    Description of the files after the jump…

    Read the rest of this entry »

    , , , ,

    No Comments

    Switch to our mobile site