Well after a little period of no posts due to being insanely busy, I thought I would share a little technique I discovered through trial and error and a little thought. Ever wanted to tween individual letters from a text field with AS3 rather than on the time line in flash? Well it is incredibly easy!
Firstly you need to create your text in the Flash authoring tool, and then after adding the text field to a container MovieClip or Sprite you simply break it apart once so that the text is separated.
Once this is done either on the main timeline or in your document class you can target the texts by targeting the container sprite's children with getChildAt(); during a for loop:
You can then add the children to their own individual container sprite as you can see and then target that sprite in order to transform any property, including filters and its stage position.
Thought I would show you how to create a simple button animation created totally in actionscript, which recreates a button animation I saw posted on a Cartoon Smart.com tutorial which was originally created on the time line. This method is very simple and easily customizable.
The artwork for the button is created in the Flash authoring tool, although it could easily be created with code as it is just a rectangle with rounded corners with a simple gradient fill.
This is exported for actionscript once it is converted to a movieclip and then in the class file I have added a ROLL_OVER event listener, you'll also notice I have added a drop shadow just to make it look cool.
Now the cool blurring animation is created by defining a variable which sets out my target blurX, this is defined in the variable targetX, which I have set to 80. Now as I want the animation to last one second, which in this case is 40 frames, I have created a variable called bx which is defined by targetX divided by the frame rate. An ENTER_FRAME event listener is added once the mouse rolls over the button and in this loop, bx is added to the blurX each frame thus increasing the amount of blur until it reaches its target blur.
Then for the Roll out animation, I have just done the opposite by starting the blur y at 50 and then each frame reducing it by a set amount until it rests back at its starting point. Nice and simple and lots of fun to play with. Source is here
After trawling the Web for various bits of information and tutorials for various ideas I have noticed how amazingly, so many tutorials are still being created for AS2 applications considering the power and superiority of AS3 so I have decided to convert a few of them to AS3 format, partly for myself and for content for this blog but also because I feel that it is important that more of the people that are still clinging onto the old AS2 days start to embrace AS3 and realise how simple to use it really is.
So, I came across this when doing a project for someone, who requested an effect and directed me towards an AS2 tutorial to outline the effect he was looking for.
The desired effect was to produce a neon text, flickering on and then off in a realistic fashion. This is all done in Flash CS3 / CS4.
Firstly the artwork needs to be produced. As flash is vector based it is best and simplest to produce the images in flash itself. This is very simple as it is only text broken apart into shapes. There are just two movie clips the first is the text in its “off” state. So we need to create a new symbol by selecting “Insert / New Symbol” or by pressing Ctrl or Opt / F8. Give it a simple name like neon_off or something. Firstly choose the text tool and in the centre of the stage add the necessary text. Then press Ctrl or Opt / B to break it apart once and separate the letters, then again to break it apart and turn it into shapes. Once this is done you can then with the stroke tool add a stroke to the edge of each of the letters with the settings illustrated.
Now we need to produce the the “neon on” text, this is done in the same way but we need to give the the text a coloured stroke and a white fill so that when the filters are applied it looks like a glowing neon light. Now these MovieClips along with the sound file which will be used when the text is flickering on need to be given a linkage so that they can be modified via ActionScript. This is done by selecting the MovieClips in the library, right clicking and selecting the MovieClip and ticking the box “Export for ActionScript” and giving it a class name.....as illustrated.
Now its time for the fun......the ActionScript.........
In AS3 the script is usually done in a separate file which the FLA links to at compile time and brings the script into the swf. So if we open a new ActionScript file and call it Flicker. We then start the file by the opening Package declaration and by importing the necessary libraries ......
We then need to create the variables needed in AS3 as each instance is first created as a variable and then addressed or added in a function. Notice the variables which create instances of the MovieClips we created earlier.
privatevar blur:BlurFilter = new BlurFilter(5, 5, 2);
Now we are going to instantiate the timer which was firstly created as a variable and add an event listener to listen for the completion of the timer and then trigger the flickering this is done like so:
Now for the flicker effect. At the moment the coloured MovieClip is on top of the grey one but it is set at an alpha of zero, once the timer has triggered its listener will add and Enter_Frame event listener which does what it says on the tin....each frame it will trigger its function and the function is as follows:
What this does is each frame give the alpha of the coloured MovieClip a random alpha, once the alpha reaches a certain level, in this case almost the highest figure it can create, the enter frame listener is removed and another one created whilst the text flickers at a higher alpha ( to give the effect of being on and flickering whilst being on) and another timer is triggered which waits to switch the flickering off and start all over again......Finally of course before we finish we need to make sure that the document class of the fla is set to target the Flicker.as, which is done by adding the document class name in the document properties tab, by just clicking on the stage and opening properties.
Originally from a fine art background, it took me a while to get in to the world of digital media, but now that I have, Flash has become my tool of choice. For the last 2 years I have been working as a freelance flash designer / developer and I now work as a Rich Internet Applications Developer for a well know communications company and strive to create engaging and creative applications for the web.
This site has become a medium for me to share my experiences and what I have learned with other flash and actionscript enthusiasts, in the hope that maybe what I have to show may help others in their working lives.