Noob Flash Rss

ActionScript 3.0 onEnterFrame

28

Posted by Aaron | Posted in ActionScript | Posted on 30-04-2007

In ActionScript 3.0, the frame event model has been changed from the ActionScript 2.0 version quite a bit. In ActionScript 2.0, if you wanted to perform a task every time you entered a frame, you would type

onEnterFrame = function(){
   trace("Do Something");
}

In ActionScript 3.0, you must use an event listener format to perform a frame event. For example…

addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
	trace("Do Something");
}

It’s a little more complicated than the old way, but ActionScript 3.0 opens up a whole new world of programming possibilities.

Related posts:

  1. Load XML in Flash (AS3)
  2. Using the MouseWheel to Scroll in AS3
  3. Tips For Migrating Your Flash Applications to ActionScript 3.0
  4. Using the ActionScript 3.0 Debugger
  5. Default Parameter Values in AS3

Comments (28)

I agree, it opens up way more doors. It will just take me a bit of time to get used too it. On the bright side I’m feeling more and more like a real programmer with 3.0. lol.

Now AS is more complicated, good for programmers, bad for designer

I think it will just be like the days of the dot notation switch, there is a learning curve but eventually the designer and the programmer will meet in the middle. I think what Adobe has to do now is stop moving forward for awhile and let us all catch up. If anyone remembers Director, this is what killed Director. Macromedia kept coming out with the “New and Improved methods” before you knew it the books were 12 inches thick and eventually people said screw this!!! and when to something SIMPLE and FAST which at the time was Flash. So I agree AS3 is better, but if AS4 comes out and it again is completely different – I will drop Flash like a bad habit and never look back. and start using SIMPLE and FAST which right now looks like it’s going to be Microsoft’s Blend, Visual Studio and Silverlight (WPF) Trinity.

I have developed out in silverlight and with version 1.0, it is not ready to compete at the level with flash. It doesn’t have anything equivalent to the flash movie clip for example. Reusing a single storyboard on multiple buttons etc requires custom javascript to modify the storybaord’s targets to match whatever you rolled over. It is all doable, but it version 1.0 isn’t quite there yet. I look forward to when it is there though because silverlight has promise. I for one am really curious to see how the battle between Flex and Silverlight is going to shape up.

can you help me with a code? iam trying to make a button wich expands when mouse roll on it and collapses when mouse is rolled out :\ thx for help

this.stop();

import flash.events.*;

var rewind = 2

this.addEventListener(Event.ENTER_FRAME, enterf);
function enterf(e:Event){
if(rewind == 1){
prevFrame();
}
}

this.addEventListener(MouseEvent.MOUSE_OVER , over)
function over(event:MouseEvent){
var rewind = 2;
play();
}
this.addEventListener(MouseEvent.MOUSE_OUT , out)
function out(event:MouseEvent){
var rewind = 1;
}

btw .. the problem was that button stops expanding and dont collapsing :\

Doing AS3 in Flex is pretty neat.. at first it’s weird with no UI based IDE, like someone pulled the floor out from under you.

Then once you get the hang of it, the freedom and intellisense is awesome. The libraries of code out there from the communities are great.. And these blogs and boards of course are the grease in the cogs. Nice work

Is onEnterFrame still the best way to have something executing constantly ?

i.e : I have a sprite I want it kinda floating around randomly on the screen, I have my OnEnterFrame event listener running my MoveStuff(), it’s works.. but is this the best way to acheive this ?

I’m totally new to actionscript 3.0…i’m trying to load an external swf file with a frame event, into a movieclip on the mainstage. How do i go about doing this…I could do it in actionscript 2.0 with loadmovie(); but this is all rocket science to me now. PLEASE HELP!

AS3 is a bad idea.
The AS2 is better than AS3 for designers, but who using flash? – Designers. Adobe should be changing AS for designer.

I completely agree with Damon Sanchez. Flash is going the same (wrong) way as Director did with ‘lingo’. Every time Adobe make actionscript ‘better’, it takes me months to catch up. I’ve completely ignored 3.0 until now because it’s so completely different to 2.0. Flash has always been for designers, why change it? There are much better apps and scripting languages out there for developers. Flash has (had) it’s niche – it was a great lightweight middle-ground between design and development and it worked a treat. Now, if Flash was able to do incredible things thanks to the new scripting language I’d understand.. but it’s just making simple tasks harder for people like me (designers) and more familiar for developers (not me). At the same time, though, Adobe are automating simple operations, like tweening (both via scripting and now, with CS4, during authoring). Ridiculous. Yes I could stick to 2.0 but then I’d fall behind – which you can’t afford to do in this industry.
They’re trying to stay one step ahead of their new competition BUT by making people learn a new scripting language, aren’t Adobe risking their users switching to a new app since they’re learning a new language anyway? And what about in education? How are students ever going to learn when their teachers are just as new to it as they are?
Not happy.

@maroon

AS3 is not bad, and Flash is not used exclusively by designers (I’m a designer myself BTW). The Flash platform is now a viable and efficient solution for developing and deploying desktop and internet apps.

Actionscript is now an object orientated language, and anyone worth their salt will tell you that OOP development (despite a steeper learning code) is the *only* way to develop feature rich media.

It really annoys me when people knock AS3 saying it sucks – just because you don’t understand it and have to change some of your (bad) design/development habits to industry recognized standards is no reason to dismiss such a much needed update to the language.

Luckily for you ludites, Adobe is creating another Flash IDE called ‘Flash Catalyst’, aimed at allowing designers to quickly create functionality without having to touch code (http://labs.adobe.com/technologies/flashcatalyst/). It looks like a good app, and fits nicely into the design > develop > deploy process – hopefully it’ll stop whining little peons like you from banging your pretty little heads against brick walls.

doh!

that should be ‘…steeper learning curve…’

AS3 Sucks

Thanks for that constructive input Mike.

Action Script 3 is powerful, but not close in power and measure to other OOP languages like ASP.Net C#. So I guess where my complaint is, if Adobe is going to drop a bomb on us, then do it… and get it over with… make Action Script just-as-if-not more powerful than C#. But the steady incremental changes with each incarnation being holistically different than the next is driving me nuts. Again I’m complaining because it took me a year to relearn AS3, I’m happy now going all Kung Fu on Problems but dude, if AS5 is holistically different than AS3 —I’M DONE WITH ADOBE and moving on to Silverlight WPF and Blend. Which by the time AS5 comes rolling about will have as much ubiquity as SWF.

PapaJ is right but AS3 still sucks!

Large clients want Flex based RIAs these days… “pretty” photo showcases and “sticky” banners are no longer in demand. You can’t impress folks or make a dime anymore with some whiz-bang AS2… I’ve been working with flash for 9 years so AS3 was a MASSIVE hit to my way of thinking, pride, my whole mantra really and wow has it opened doors that I NEVER thought would be available to me. I was forced to adapt, because eating is important to me, and it turned out to be a blessing to any existing AS2 developer who commits to AS3. Everyone else is falls in the much needed washout category in my mind. The industry needed a purge though ;) .

-m

Hi chaps,
I have a big problem.
I try to move on and start using AS 3.0
Here is what i need.
On enter frame load an external swf file.
When the time line hits frame 20, “ delete onEnterFrame (remove the swf file)”.
On Frame 21 load different swf file, when it hits frame 50, gotoAndStop(1);
Can somebody make my day?
Thanks in advance.
John

I have managed to create the swf file which will load other swf files after 5 secs.
What i need now is: after 5secs the first swf file to be removed and on the next frame to upload a new swf file bu just changing the
var my_next_swf:URLRequest = new URLRequest(“swf1.swf”);

to

var my_next_swf:URLRequest = new URLRequest(“swf2.swf”);
and
var swf_secs:Timer = new Timer(5000, 1);
to
var swf_secs:Timer = new Timer(10000, 1);

here is the full code.

var my_next_swf:URLRequest = new URLRequest(“swf1.swf”);
var next_swf_loader:Loader = new Loader();
next_swf_loader.load(my_next_swf);
addChild(next_swf_loader);

var swf_secs:Timer = new Timer(5000, 1);

swf_secs.addEventListener(TimerEvent.TIMER, doit_next_swf);

function doit_next_swf(event:TimerEvent):void
{

nextFrame();

//removeEventListener(Event.ENTER_FRAME, ?);
}

swf_secs.start();

Could someone help me convert 2.0 to 3.0
Im screwed…

_root.onEnterFrame = function(){
if(_root._ymouse200){
myVar=true;
}
if(_root._xmouse100 and myVar==true){
imgBar.nextFrame();
imgBar.nextFrame();
} else{
imgBar.play();
}
if(_root._xmouse>50 &&_root._xmouse<350 && myVar==true){
imgBar.stop();
}
}

or better

_root.onEnterFrame = function(){
if(_root._ymouse200){
myVar=true;
}
if(_root._xmouse100 and myVar==true){
imgBar.nextFrame();
imgBar.nextFrame();
} else{
imgBar.play();
}
if(_root._xmouse>50 &&_root._xmouse<350 && myVar==true){
imgBar.stop();
}
}

please i need to convert as2 flashplayer 7.0 to as3 flash player 10.
the code is:

// Ordenadas de Origen
orig_x = this._x;
orig_y = this._y;

// Profundidad Asignada
profundidad = 20; // No olviden ajustar el valor

// Ajustamos su posición Z en la escena
this.swapDepths( profundidad );

onEnterFrame = function(){
// Obtenemos la ordenada X de destino
dest_x = ( ( ( 210 – _root._xmouse ) / 210 ) * profundidad ) + orig_x;
// Obtenemos el incremento de movimiento en X
incr_x = ( dest_x – this._x ) / 10;
// Ajustamos la posición en X
this._x += incr_x;

// Obtenemos la ordenada Y de destino
dest_y = ( ( ( 130 – _root._ymouse ) / 130 ) * profundidad ) + orig_y;
// Obtenemos el incremento de movimiento en Y
incr_y = (dest_y – this._y ) / 10;
// Ajustamos la posición en X
this._y += incr_y;
}

I’m trying to make a flash move on to a php site when it reatchen it’s end. So I tryed this but it just spams my browser with new tabs.

addEventListener(Event.ENTER_FRAME, e);

function e(event:Event):void
{
var link:URLRequest = new URLRequest(“http://www.google.com”);
}

stop();

I am as frustrated as the rest of you with learning AS3. I have a graphics degree, and picked up flash design (AS2)because it suited me better.
Now, as I am becoming pretty fast and knowledgeable at an upper intermediate level, everything I have learned is no longer applicable.

Fortunately, I have access to a lot of training videos, etc. I’ve been taking pages and pages of notes, doing side test swf projects, and making myself write out code by hand instead of copying and pasting… All to make a working navigation that loads/unloads external swf files into a container swf. Something I can do in my sleep in AS2 now seems to take hundreds of lines of redundant code because I am not used to creating generic functions/variables that can be “recycled”.

I’m still trying to figure a slick way to have an empty loader waiting for content (an external page swf) so that my button press will populate it BUT then have the next button press remove the current swf AND load the next one. Right now they are stacking on top of themselves.

Anyway, just wanted to vent because I’m the only flash guy in my group here, and no one really gets what’s happening here! :?

Here’s my button code by the way (at the moment) It’s got a lot of commented out stuff as I turn off and on different pieces of code. Oh- and please excuse my goofy naming conventions!! When it’s really late, and I’m tired, and trying to remember which part of a function/var is in my words and not as3 I try to keep a sense of humor about it!

————————————-
btn1_mc.buttonMode=true;
btn2_mc.buttonMode=true;

btn1_mc.useHandCursor=true;
btn2_mc.useHandCursor=true;

var titsLoader:Loader;
//var boobsLoader:Loader;

var urlReq:URLRequest;

var ballsUrl:String=”balls.swf”;
var boobsUrl:String=”boobs.swf”;

addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
trace(“Do Something”);
}

function Badass(ba:MouseEvent):void {
if (ba.target==btn1_mc) {
//titsLoader = new Loader();
urlReq=new URLRequest(ballsUrl);
titsLoader.load(urlReq);
mt_mc.addChild(titsLoader);
}
if (ba.target==btn2_mc) {
titsLoader = new Loader();
urlReq=new URLRequest(boobsUrl);
titsLoader.load(urlReq);
mt_mc.addChild(titsLoader);
}
}

//function unloadMovies(e:Event):void {
// removeChild(titsLoader);
// removeChild(titsLoader);
//}

btn1_mc.addEventListener(MouseEvent.CLICK,Badass);
btn2_mc.addEventListener(MouseEvent.CLICK,Badass);
————————————

This is just a side test file to see how the hell I can put in/ pull out my page swfs..
I havent gotten it to work totally yet.

Thanks for this. Very helpful.

SIMON IS A MORON. Flash has full capabilities of any other scripting language AS3 is way more logical and easy to use. they are making the program better you moron. it takes no time to learn AS3 if you know AS2. Use your brain and learn something technology is about advancement not sitting still in the same place forever.

Post a comment