Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




OnEnterFrame



I was just wondering how many onEnterFrames are kosher for a site. Does it matter? Or, does it just depend on the complexity of the code within?



FlashKit > Flash Help > Flash ActionScript
Posted on: 09-26-2003, 05:02 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

OnEnterFrame=null, OnEnterFrame=undefined & Delete OnEnterFrame....
onEnterFrame=null, onEnterFrame=undefined & delete onEnterFrame....


Which one to use??? What are the performance considerations. If all my movieclips on-stage are running a MovieClip.prototype.onEnterFrame = function() {run initial stuff before setting onEnterFrame=null/undefined... }, will there be performance hits? It's sad that delete onEnterFrame doesn't work unless I delete the prototype enterFrame as well, which would make the clips reinitailise itself again once you declare the enterFrame prototype again (i need to do this since there's more movieclips that end up appearing on-stage, and they need to automatically initialises themselves the moment they appear).

It seems that setting enterFrame to null or undefined is the safest way to go about it, since dealing with multiple .swfs would mean using the same MovieClip.prototype, which means I can't afford to flush out one zone of enterFrames (by deleting both null enterframes and MovieClip.prototype.onEnterFrame) if it means the other zones still needs to initialise their clips first...it's just too troublesome and buggy a mechanism to implement! Once MovieClip.prototype.onEnterframe is declared, it should stay. Will there be performance hits as a result of this?

Is there anyway to do this without tricking the engine to call the onLoad function for MCs by typing "//" into each movieclip actionscript box --- or by troublesomingly creating linkage-ids for every movieclip library item!? NO! That's not what i want...they'll only add to the fiile size! How do i execute a certain "constructor/initilisation" function to all Movieclips without linking them to a class in a library? Something to think about.....

What Difference Between Mc.onEnterFrame And Funtion OnEnterFrame()
Dear, All,
Could anybody tell me the difference about them, I am fresh......

thanks in advance

Problem With OnEnterFrame And Delete OnEnterFrame
Ok here is the nuts of the problem,

When I delete the onEnterFrame function programatically I can't reassign it later.

Here is what is happening:
I have a method that I call to build a box on the screen over time. I build it overtime using the onEnterFrame function.
When the application is done it delete the onEnterFrame just fine.

Everything works as expected until you try to assign the same method over again to say for instance make the box smaller. Once I try to call it again I can't assign the onEnterFrame again... I have no idea why it is totally strange.


Code:
//Create an interface
//mc:MovieClip, x:Number, y:Number, w:Number, h:Number
InterfaceBuilderClass.prototype.createInterface = function(mc,x,y,w,h)
{

mc.dy = (h/2)*-1
mc.dx = (w/2)*-1
mc.dy1 = h/2
mc.dx1 = w/2
mc.NFRAMES = 40;
mc.controller = this;
mc.t = 0;

mc.onEnterFrame = function()
{
if (this.t++ < this.NFRAMES) {
trace(this.t);
//DELETED DRAWING STUFF THAT IS NOT AFFECTING THE PROBLEM

}else
{
//redraw with rounded corner
//DELETED DRAWING STUFF THAT IS NOT AFFECTING THE PROBLEM

this.controller.executeCallBack()
delete this.onEnterFrame;
}
}
}

Try it for yourself and see if you can make it work.

If anyone else has run into this problem I'd love to know how you resolved it.

Thanks,
Mark

Re-initialising OnEnterFrame After Deleting OnEnterFrame
Hello to all the actionscript guru's!

I have this thing where when I click this other thing which is controlled by a different thing which gets deleted after I click the other thing and I would like to know if I can sort of undelete the different things thing????

Okay, now in English.

I have some movieclips that move using an onEnterFrame. When you click on a movieclip, I stop the movement by deleting the onEnterFrame. Is there a way to re-initialise the onEnterFrame to get the movieclips moving again?

A thanks in advance for everyone who reads this question

Delete OnEnterFrame; Start OnEnterFrame?
Hi, title says it all.... any consise methods to restart a deleted onEnterFrame that has been deleted?

Thanks!

Delete OnEnterFrame Re-establish OnEnterFrame
i'm trying to stop an onEnterFrame [via the delete onEnterFrame] but later re-establish it, or restart it. is this even possible?? anyone got suggestions if it ain't??

[F8] OnEnterFrame Inside OnEnterFrame
this is a simplification of what I have:

function fadeOutBorder(thumbnail){
this.onEnterFrame = function() {
if(this["thumbnail"+thumbnail]._alpha>0) {
this["thumbnail"+thumbnail]._alpha-=5;
}else{
this["thumbnail"+thumbnail]._visible=false;
//delete _root.onEnterFrame;
}
};
}


function loadThumbnails(){
onEnterFrame{
//stuff here...
fadeOutBorder(5);
//when that^^ is called... it quits the rest of the script...
//more stuff here...
};
}


So what happens is when I call fadeOutBorder.. It just stops that onEnterFrame in the loadThumbnails function.

Mc.onEnterFrame = Foo() ?
I am trying to dynamically give MCs the onEnterFrame event handler. I have 4 MCs on stage each with the name: clip1, clip2, clip3, clip4. Each clip does the onLoad, but only the first clip rotates; furthermore, the trace in rotate only outputs the first clip...

Code in frame 1:

var clips = [clip1, clip2, clip3, clip4];

// Make each clip 50% alphaed onLoad
function init(s) {
s._alpha = 50;
}

// Rotate each clip 5 degs onEnterFrame
function rotate(s) {
trace(s);
s._rotation += 5;
}

for(i in clips) {
s = clips[i];
s.onLoad = init(s);
s.onEnterFrame = function() {
rotate(s);
}
}

Any thoughts?

tx!

Onenterframe
I using a bit of actionscrpt I found from your message boards which I then changed and began to understand. It was for making a menu come into the screen when pressing space. The problem I have is after it has loaded you have to click on the frame to make the menu come in when space is pressed. I believe it is something to do with the "onenterframe".

this is the code:

menu.onEnterFrame = function() {
if (Key.isDown(Key.SPACE)) {
if (menu._x<0) {
menu._x += 20;
}
} else {
if (menu._x>-80) {
menu._x -= 20;
}
}
};

have tried to change it to "onLoad" but that does not seem to be it. Would love any help as this has been driving me mad of days. my website www31.brinkster.com/anpond/ that is the old one. The one I am going to replace it with is www31.brinkster.com/anpond/movie/ Thanks for your help.

OnEnterFrame
Hey,

I'm jus' learning the onEnterFrame stuff...

And I've got a problem:
Why cant I use more then 1 onEnterFrame per MC?

The reasong I'm asking this is because I have different types of code, and to make the code better to look at, I want to store the code on different layers, so I would also need more then 1 onEnterFrame events... but I can't get it to work... is there a way to solve it or something?

Getting Out Of A OnEnterFrame()?
Hi all!

I am having problems getting out of an onEnterFrame(). What I want to do is making a movieClip invisible, but once the ._alpha is below 0 I need to break out of the onEnterFrame(). However, I cant seem to get it rigth!

Here is some code:
code:
instance.onEnterFrame = function(){
instance._alpha -= 20;
trace("alpha is"+instance._alpha);
if (instance._alpha < 0) {
return;
}
};


Hope there is any help out there!

Ciao ciao

OnEnterFrame
Hi

I use movieclip placed in first frame of scene:

onClipEvent(enterFrame){}

I want to know how to use button to execute this movieclip in place of using onClipEvent(enterFrame).

Thanks a lot

Mc.onEnterFrame
why is this only being run once, not every frame?

mc.onEnterFrame = myFunctionName();

function myFunctionName() {
mc._x-=10;
};

OnEnterFrame Use
Hi There,

I've been using a tutorial from flash kit to help me learn a bit more about using sound, and have come across a bit of code that i've assumed works in the same way as an onClipEvent handler but is placed on a single stopped frame rather than on an MC.

I just needed to know if this is correct as I can't find any referance to it in any of my scripting books:

this.onEnterFrame=function() {
if (playing==true) {myText02="play"}
if (playing==false) {myText02="stop"}
}

Thanks for any help

Parish

[AS] OnEnterFrame
I can navigate forward and back allong my movie. I want this code to be triggered if I land somewhere in the second half.
this code sits in a keyframe that runs the length of the second half of my movie

Code:
moveLeft.onEnterFrame = function() {
if (_root.mainScreen01._x >= -55) {
_root.mainScreen01._x -= 10;
}
}
canvasMoveLeft = setInterval(moveLeft,20);
At the moment it only works if I just play the movie through from beginning to end.
any thoughts?
Thank you,
Tim.

For And OnEnterFrame
I have instanced 11 movice clips : bg1, bg2, etc...
No i have this on the main timeline
code:
for (j=1; j<=100; j++) {
_root["bg"+j].onEnterFrame = function() {
if (_root["bg"+j].areahit.hitTest(_root.trashplayer.hitarea) and _root.yspeed>0) {
_root.trashplayer._y = (_root["bg"+j]._y-(_root["bg"+j]._height/2))-2;
if (_root.yspeed<0) {
} else {
_root.jump = true;
_root.jumpback = true;
}
_root.yspeed = 0;
_root.trashplayer._y -= 1;
}
if (_root.doneonce != true) {
if (_root["bg"+j].areahit.hitTest(_root.trashplayer.hitarea)) {
_root.trashplayer._y = (_root["bg"+j]._y-(_root["bg"+j]._height/2));
_root.doneonce = true;
}
}
if (_root.ff) {
_root["bg"+j]._x -= _root.scrollspeed;
}
if (_root.rr) {
_root["bg"+j]._x += _root.scrollspeed;
}
if (_root.up) {
_root["bg"+j]._y -= _root.scrollspeedy;
}
if (_root.down) {
_root["bg"+j]._y += _root.scrollspeedy;
}
if (_root.shake) {
_root["bg"+j]._x += _root.shakex[_root.i];
_root["bg"+j]._y += _root.shakey[_root.i];
}
};
}

Why the F*ck do the mcs not move? I have put a trace action after
if (_root.down) { , and it got traced, so apparently the moving is having a problem.. putting this instead of _root["bg"+j] makes the entire time line move...help

HELP: OnEnterFrame
Hi,
I am trying to manipulate 200 different layers at once within a movieclip. (each layer represents a person and as the movie progresses they flow towards a common destination)
My problem is that I currently have all 200 layers being moved within one onEnterFrame() function which then contains a for loop - looping through each 200 people (on each layer) and updating their x/y co-ordinates).
This seems to be very slow and cause jerky movements - presumebly due to on every frame it has to loop through and update 200 layers!

Is there a better way of doing this?
Have tried calling 200 dif onEnterFrame functions at start within a for loop but this doesnt work.
Have also considered the onInterval function but has same problem?

Any advice? HELP!!

Cheers,
Brad.

OnEnterFrame?
Hi,
I am trying to manipulate 200 different layers at once within a movieclip. (each layer represents a person and as the movie progresses they flow towards a common destination)
My problem is that I currently have all 200 layers being moved within one onEnterFrame() function which then contains a for loop - looping through each 200 people (on each layer) and updating their x/y co-ordinates).
This seems to be very slow and cause jerky movements - presumebly due to on every frame it has to loop through and update 200 layers!

Is there a better way of doing this?
Have tried calling 200 dif onEnterFrame functions at start within a for loop but this doesnt work.
Have also considered the onInterval function but has same problem?

Any advice? HELP!!

Cheers,
Brad.

Please HELP - OnEnterFrame
Hi,
I am trying to manipulate 200 different layers at once within a movieclip. (each layer represents a person and as the movie progresses they flow towards a common destination)
My problem is that I currently have all 200 layers being moved within one onEnterFrame() function which then contains a for loop - looping through each 200 people (on each layer) and updating their x/y co-ordinates).
This seems to be very slow and cause jerky movements - presumebly due to on every frame it has to loop through and update 200 layers!

Is there a better way of doing this?
Have tried calling 200 dif onEnterFrame functions at start within a for loop but this doesnt work.
Have also considered the onInterval function but has same problem?

Any advice? HELP!!

Cheers,
Brad.

OnEnterFrame
I have this code on the first frame inside a mc.
------------------------------------------------------------------
reedstartX=reed._x;
reedstartY=reed._y;

function reedani() {
while (breakwhile == false) {
reed.onEnterFrame = function() {
reed._x = this._x+1.6*5*accel+1.6*(.5*-2*accel*accel);
reed._y = this._y+5*accel+1*(.5*-2*accel*accel);
accel = accel+.5;
trace(reed._x);
if (reed._x<reedstartX) {
reed._x = reedstartX;
reed._y = reedstartY;
breakwhile = true;
}
trace("reedanirunning");
};
--------------------------------------------------------------------

as of now when i call the reedani function, its an infinite loop so i can't even see if my logic is right. I'm not sure what (name).onEnterFrame=function(){ blah}; does. "reed" is an mc inside the same clip. Can onEnterFrame be used this way? If so, what am i doing wrong.

This.onEnterFrame
alright. I have this preloader which is preloading a movie. The only problem is that my code doesn't seem to be going. From what I can tell it works all up until the point I get to the line
code:
this.onEnterFrame = function () {

I will post the fla here so that you can see the preloader. And here is the code.
code:
loadText = "";
this.fill_in._visible = false;
this.fill_in._xscale = 0;
this.loading._visible = true;
this.graph._visible = true;
this.loadBar._visible = true;
this.createEmptyMovieClip("container", 5);
trace ("I got this far");
container.loadMovie("file:///C|/Kesler's File/Name_Movie.swf");
this.onEnterFrame = function() {
percent = Math.floor((this.container.getBytesLoaded()/this.container.getBytesTotal())*100);
trace (percent);
if(!isNan(percent)){
if(percent == 0) {
loadText = "";
} else {
loadText = percent + "% Loaded";
this.fill_in._xscale = percent;
}
this.loadBar._visible = true;
this.graph._visible = true;
this.loading._visible = true;
} else {
if (percent == 100) {
loadText = "";
this.loadBar._visible = false;
this.graph._visible = false;
this.loading._visible = false;
loadMovieNum("file:///C|/Kesler's File/Name_Movie.swf", 0);
}
}
};
stop();

OnEnterFrame _x _y / Help Me Please...
Hi all,

in this code:

this.onEnterFrame = function() {
_x = (_x + (X - _x) / 8);
if (_x >= (X - 1) && _x <= (X + 1)) {
_x = X;
_y = Y;
this.onEnterFrame = undefined;
}
};


I need exactly to define position of object. Example x = 400 y = 500.
Is someone gonna help me?

OnEnterFrame
Does anyone know how to attach onEnterFrame commands to movie clips and/or assign them an ID someway so that if you have multiple onEnterFrames running they're not all deleted when you run the delete onEnterFrame command?

OnEnterFrame Help
I am using the following code with my flv to attach some movieclips, but the movieclip open_close_mc, does not play. The coverPlate_mc gets moved, so I am assuming that the other movieclips are being attached.

Can a movie clip play from an onEnterFrame function?



Code:
_root.stop();
var netConn = new NetConnection();
netConn.connect(null);
var ns = new NetStream(netConn);
my_video.attachVideo(ns);
ns.setBufferTime(5);
ns.play("videos/g2_crush_raw.flv");
// adjust flv volume
this.createEmptyMovieClip("flv_mc", this.getNextHighestDepth());
flv_mc.attachAudio(ns);
var audio_sound8:Sound = new Sound(flv_mc);
audio_sound8.setVolume(audio_sound8.getVolume()+100);
updateVolume();
//
getTotalTime = function () {
ns.onMetaData = function(obj) {
_global.videoDuration = obj.duration;
trace(obj.duration);
};
};
onEnterFrame = function () {
getTotalTime();
totalPlayingTime = Math.round(_global.videoDuration);
currentPlayingTime = Math.round(ns.time);
trace(ns.time);
if (ns.time>=10) {
//move the cover plate
coverPlate_mc._x = -300;
//add the cover ring
attachMovie("ring_mc", "RC", 20);
RC._x = 4;
RC._y = 73;
//add the open-close sequence
attachMovie("open_close_mc", "MC", 10);
MC._xscale = 34;
MC._yscale = 34;
MC._x = -32.1;
MC._y = 65.3;
//add the gman
attachMovie("gman1_mc", "GMAN", 5);
GMAN._xscale = 30;
GMAN._yscale = 30;
GMAN._x = 37;
GMAN._y = 90;
}
if (totalPlayingTime == currentPlayingTime) {
// ns.seek(0);
// ns.pause();
ns.close();
gotoAndPlay("next10");
}
};

OnEnterFrame Help
I have an onEnterFrame function that I need to find a better way to handle becuase my code is getting increasingly complicated. What I am doing is using the onEnterFrame function to keep track of my FLV time. At certian intervals I need certian movie clips to play. So I have been working on away to clean up the code. Not to mention flash will not autoformat a function in a function.

Is there a way to stop the onEnterFrame function (or do this entirely in a different way), do something and then restart it. In the code below you can see I am running into mutiple "if" statments.


Code:
_root.stop();
var netConn = new NetConnection();
netConn.connect(null);
_global.ns = new NetStream(netConn);
my_video.attachVideo(_global.ns);
_global.ns.setBufferTime(5);
_global.ns.play("videos/g2_crush_raw.flv");
// adjust flv volume
this.createEmptyMovieClip("flv_mc", this.getNextHighestDepth());
flv_mc.attachAudio(_global.ns);
var audio_sound8:Sound = new Sound(flv_mc);
audio_sound8.setVolume(audio_sound8.getVolume()+100);
updateVolume();
//
getTotalTime = function () {
_global.ns.onMetaData = function(obj) {
_global.videoDuration = obj.duration;
// trace(obj.duration);
};
};
//
onEnterFrame = function () {
//
startTimer();
//
if (_global.ns.time>=10) {
trace("test");
delete onEnterFrame;
//
changeTitle("YOU'RE LOSING MONEY");
//
openGman();
//
// add the gman
_root.attachMovie("gman1_mc", "GMAN", 5);
_root.GMAN._xscale = 30;
_root.GMAN._yscale = 30;
_root.GMAN._x = 37;
_root.GMAN._y = 90;
//
onEnterFrame = function () {
startTimer();
// close stuff
if (_global.ns.time>=20) {
delete onEnterFrame;
//
closeGman();
//
onEnterFrame = function () {
startTimer();
}
}
}
}
};
//
//
//
// open gman
function openGman() {
// move the cover plate
_root.coverPlate_mc._x = -500;
// add the cover ring
_root.attachMovie("ring_mc", "RC", 20);
_root.RC._x = 4;
_root.RC._y = 73;
// add the open sequence
_root.attachMovie("open_mc", "MC", 10);
_root.MC._xscale = 34;
_root.MC._yscale = 34;
_root.MC._x = -32.1;
_root.MC._y = 65.3;
}
// close gman
function closeGman() {
_root.MC.removeMovieClip();
_root.attachMovie("close_mc", "AC", 10);
_root.AC._xscale = 34;
_root.AC._yscale = 34;
_root.AC._x = -32.1;
_root.AC._y = 65.3;
}
// change title
function changeTitle(title:String) {
// set chapter text
_root.chapter.chapter_w.autoSize = true;
_root.chapter.chapter_w.text = title;
_root.chapter.chapter_b.autoSize = true;
_root.chapter.chapter_b.text = title;
}
//
function startTimer() {
getTotalTime();
totalPlayingTime = Math.round(_global.videoDuration);
currentPlayingTime = Math.round(_global.ns.time);
flv_time.text = _global.ns.time;
}

OnEnterFrame?
Hi there,

Im trying to make this thing - that when this keyframe is arrived at, that the film has two options depending on whether a global variable is true or not. If that variable is true, it stops() at that keyframe. If it isnt true, it goes to and plays ("printos"). Only I dont have a clue of the correct syntax - my best bet would be the one below, but it doesnt work. What would be the correct way to write this please?


function.OnEnterFrame();
if(_global.printer == false){
gotoAndPlay("printos")
{
if(_global.printer == true){
stop();
}
}

Onenterframe
Please see the script below:

function moveSquare (whichSq, fade) {
whichSq.onEnterFrame = function(){
whichSq._alpha += (fade-whichSq._alpha)/3;
}
}

sq1.myButton.onPress = function(){
moveSquare(sq1, 100);
moveSquare(sq2, 0);
moveSquare(sq3, 0);
moveSquare(sq4, 0);
moveSquare(sq5, 100);
moveSquare(sq6, 100);
moveSquare(sq7, 100);
moveSquare(sq8, 100);
}

I have 8 squares on the page 4 start visible the other 4 are at alpha value 0. When the button is pushed the 4 visible change to 0 alpha and vice versa. The script works fine, but I want the 4 to fade in only when the first four have reached 0 alpha, at the moment they all change at the same time.

thanks for any help

OnEnterFrame
Hi everybody.

I am attempting to place an "onEnterFrame" script on an MC that I am loading ext. swfs into. Once something is loaded into the MC, I can not get it to work. Any hints?? Here is two versions of the script:
code:
//this traces once
holder_mc.onEnterFrame = function() {
trace("hi");
}
holder_mc.loadMovie(_root.myXML.vidList_0[0]);

//this does not trace at all
holder_mc.loadMovie(_root.myXML.vidList_0[0]);
holder_mc.onEnterFrame = function() {
trace("hi");
}

The only difference being the order... how can I get it to "stick" once the swf is loaded??

Thanks for any help,
1M.

End OnEnterFrame?
How do you get out of an onEnterFrame

I have a movie that makes something._alpha -= 20 untill the alpha <= 0. once i do that it removes the movie clip. But how do i exit the onEnterFrame loop, because once i do it again, since its still looping, it fades it out and takes the movieclip away.

So How do i exit an onEnterFrame function?


Code:
if (percentage == 100) {
onEnterFrame = function () {
loading._alpha -= 20;
if (loading._alpha<=0) {
percentage = 0;
loading._alpha = 100;
removeMovieClip(loading);
}
};
}

Help With OnEnterFrame Plz.
Hi, this code below, I use to make the car move and when it hits the Tree
the car explodes.
The problem is , I want to stop the car from moving as it hits the tree,
and so far struggling with it, any help would be very nice

on (release, keyPress "<Right>") {
car_mc.onEnterFrame = function() {
car_mc._x += 10;
if (car_mc._x>550) {
car_mc._x = 0;
}
if (_root.tree_mc.hitTest(car_mc) == true) {

_root.car_mc.gotoAndPlay("explode");

}
};
}

[F8] OnEnterFrame
This is my code:


Code:
this.onEnterFrame = function(){
if (_global.position == "start" && _global.door != "open" && _global.light != "on" ) {

_root.movie1_mc.gotoAndPlay ("start")
delete this.onEnterFrame;
}
}


This code seem to only work once! When the if statement all satisfy those conditions again, movie1 doesnt play. BUT when I did a 'trace a msg' the msg traced fine. So I dont understand whats going on?

[F8] OnEnterFrame And XML
Well I thought this was going to be easy but here I am on the board!

Simple timeline looking to load external images from an xml file into empty movieclip with the image switching when it reaches specific frames. I have the xml file loading and working okay and some dynamic text (also from the xml file) works fine but the image won't load. Here is the code I am using...

on the initial frame:

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.onLoad = loadXML;
xmlData.load("content.xml");

this.onEnterFrame = function() {
picture._alpha = 100;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
}


Then on sequential frames where the image and text should switch...

this.onEnterFrame = function() {
picture._alpha = 100;
picture.loadMovie(image[1], 1);
desc_txt.text = description[1];
}

And so on with the array increasing when the next switch occurs. As I said Text works fine but no images... I can load an image in using a seperate function and hardcoding the url so I know the paths are right. HELP ME!

Thanks guys,
dptoot

How Much Is Too Much (to Do On An OnEnterFrame)
how much code do you need to be running on an onEnterFrame to get a significant performance issue? i currently have 21 lines and it seems ok, but am about to add more and am worried it'll start to chug. any thoughts?

[CS3] Would I Use A OnEnterFrame For This?
Hello,

I am using variables to control things, like this,

on (release) {

test = 4;

if (Number(test) == 4) {
home_btn_main.enabled = true;
about_btn_main.enabled = true;
gallery_btn_main.enabled = true;
contact_btn_main.enabled = false;
}

As you can see I define test = 4; with a on (release) action.

What I'm trying to do is put AS in a frame to make test = a number; when the timeline plays it. So, define test without a on () action, just define it when it plays it.

Would that be something like

onEnterFrame(){
test = a number;
}

I think I'm not understanding onEnterFrame though...

OnEnterFrame Within OnEnterFrame
OK . Code will loop within an onEnterFrame. And if another onEnterFrame is place within the first one, the code within that one will then loop instead. From here if I want to break out of the onEnterFrame, the delete function is used. My problem is that I only want to break out of the centre onEnterFrame and then resume looping the first one. Is this possible?
Seems the onEnterFrames could be side by side, so it exits out of oneand then enters into another, but I don't want to do it for this project.

Here is some simple code, in hope to get the answer some for my bigger project. Unfortunately this one breaks out of both onEnterFames - instead of onecode: loadMovie ("otherinfo2.jpg", myTitle);
onEnterFrame = function (small)
{
trace ("small");
this.onEnterFrame = function (big)
{
if (myTitle.getBytesTotal () == myTitle.getBytesLoaded () && myTitle._width != 0)
{
myTitle._height = 400 / (myTitle._width / myTitle._height);
myTitle._width = 400;
delete this.onEnterFrame;
}
};
};

How To Use OnEnterFrame?
Hi all,

I have attached a small alpha = 0 rectangle MC onto my mouse cursor. Like this:

onEnterFrame = function (){
attachMovie("dragger","dragger",10);
dragger._x = _xmouse;
dragger._y = _ymouse;
}

It works.

After which, i want to detect if there is a hitTest between the dragger MC and other MCs, with a mouse click, I want to drag the MCs, named 'meat'. Thus I did this:

dragger.onPress = function (){
onEnterFrame = function (){
if (dragger.hitTest(meat)){
meat.startDrag();
}
}
}

However, it doesn't respond. I gathered that it is the 'onEnterFrame' problem. When I take away the first portion of the coding, which is attaching dragger, meat MC can be dragged. After I added in, it can't.

Anyone knows what Im saying and can provide any solutions?

Thanks

Regards
Victor

How Do I Use OnEnterFrame?
Hi,

I'm fairly new to ActionScript. I was given an assignment in class. The assignment is to load five instances of a movieclip (_movieclip in library) using attachMovie, and have them placed vertically in a line, starting from (50,50). The clips are required to be in an array.

When a button on the stage is pressed, the first clip has to start playing, move horizontally to (550,50), and then stop playing, as well as its movement. Than, the second clip has to do the same horizontal movement. We were asked to use onEnterFrame in the example.

I tried a bit, and got the first clip to move. I have problems getting the others to move. Here's the code. Can anyone tell me how onEnterFrame really works?


PHP Code:



var mov_arr:Array=new Array();
var index:Number=0;
var ycoord:Number=50;

for(i=1;i<=5;i++) {
    var linkName:String="sample"+i+"_mc";
    _level0.attachMovie("_movieclip",linkName,getNextHighestDepth(),{_x:50,_y:ycoord,_width:50,_height:50});
    ycoord+=60;
}

mov_arr=[sample1_mc,sample2_mc,sample3_mc,sample4_mc,sample5_mc];

for(i=0;i<5;i++) {
        mov_arr[i].stop();
}
    
play_btn.onRelease=function() {
    for(i=0;i<5;i++) {
        mov_arr[index].onEnterFrame=function() {
            mov_arr[index].play();
            if(mov_arr[index]._x<550) mov_arr[index]._x+=10;
            else {
                index++;
                mov_arr[index-1].stop();
                mov_arr[index-1].onEnterFrame=null;
            }
        }
    }


I'm Going Mad OnEnterFrame
I can get so far then something stops me in my tracks.I'll be glad when I start a formal education for programming in August!Anyways I'm having this problem with an onEnterFrame event.My code is below;

ActionScript Code:
be.onLoad = function(){
currentPos = 0;
pos = [119,194,262,119,194,262,159,195];
currentx = 0;
posx = [55,55,55,45,45,45,40,35]
}

be.onEnterFrame = function(){
this._x = pos[currentPos];
this._y = posx[currentx];

if (currentPos>7) {
      currentPos = 0;
      currentx = 0;
    
}

}
I later tell a button.onPress function to do this

ActionScript Code:
currentPos++;
   currentx++;

Well that works fine for CurrentPos once i added currentx it killed my movie.the movie clip don't even show up on stage.I have got the trouble down to the onEnterFrame,by commenting out sections of my code.But i cant find tin that enterframe event what is causing the trouble.
Thank-you

OnEnterFrame
Hi guys. Im doing a menu that follows the menu, but i cant make it stop following the mouse. Heres the code i found at kirupa

onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
}
onClipEvent (enterFrame) {
endX = _root._xmouse;
endY = _root._ymouse;
_x += (endX-_x)/speed;
_y += (endY-_y)/speed;
}

Works great but when i try to do the delete onEnterFrame(); it doesnt work. Can someone give me a hand please?

OnEnterFrame
I would like to fire the test1 function when my first XML file is loading, then, I would to delete it and fire test2 when my second XML file is loading. And I don't know how to do that

thanks


Code:
var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success){
if (success){
delete test1.onEnterFrame
parseXML(my_xml);
}
}
my_xml.load("menu2.xml");


test1.onEnterFrame = function() {
Total = my_xml.getBytesTotal();
Lu = my_xml.getBytesLoaded();
rapport = Math.round((Lu)/(Total)*100);
_root.affichage.embedFonts = true;
_root.affichage.html = true ;
_root.affichage.htmlText = "<font face='DIN_Bold' size='24'>" + Math.round(rapport) + "</font>";
}

test2.onEnterFrame = function() {
Total = XMLContent.getBytesTotal();
Lu = XMLContent.getBytesLoaded();
rapport = Math.round((Lu)/(Total)*100);
_root.affichage.embedFonts = true;
_root.affichage.html = true ;
_root.affichage.htmlText = "<font face='DIN_Bold' size='24'>" + Math.round(rapport) + "</font>";
}

function parseXML(xml){
menuArray = new Array();
for(i=0;i<xml.firstChild.childNodes.length;i++){
langue = xml.firstChild.childNodes[i].attributes.langue;
menuArray[langue] = new Array();
for(a=0;a<xml.firstChild.childNodes[i].childNodes.length;a++){
//menuArray[langue][a] = xml.firstChild.childNodes[i].childNodes[a].attributes.label;
menuArray[langue][a] = new Array();
for(b=0;b<xml.firstChild.childNodes[i].childNodes[a].childNodes.length;b++){
//trace("menuArray[" + langue + "][" + a + "][" + b + "] = " + xml.firstChild.childNodes[i].childNodes[a].childNodes[b].firstChild.nodeValue);
menuArray[langue][a][b] = xml.firstChild.childNodes[i].childNodes[a].childNodes[b].firstChild.nodeValue;
}
}
}
var XMLContent = new XML();
XMLContent.ignoreWhite = true;
XMLContent.onLoad = function(success){
if (success){
parseXMLContent(XMLContent);
}
}
XMLContent.load("content.xml");
}

NaN And OnEnterFrame
This is probably really simple, but i'm stumped. I have the following code on the first frame of a MovieClip object:


Code:
var vy:Number;
var hit:Boolean

onEnterFrame = function()
{
trace(vy);
if(hit)
{
dis = this._y - 300;
vy = ((2*dis)/30);
}
}
"hit" is based on an external event, and i think not important in the problem. But after vy is updated from this event, the trace statement returns NaN.

Any ideas?

Cheers,

dannyW

When To Use OnEnterFrame?
I'm working on this flash piece where I'm inside a movie clip in the second frame of the main timeline and basically I want to tell flash that when you enter this frame, you need to go to the first frame of the main timeline without any action required by the user. The code I am using is:

Box1_mc.onEnterFrame = function () {
_root.wait_mc.gotoAndPlay(1);
};

While it seems this would work to me, it just takes me back to the first frame of that movie clip and it keeps repeating itself. Does anyone have any ideas?

Thanks in advanced.
Shanna

OnEnterFrame
Hello,

I've created a button and added an event listener to it. -- Works great.
Now I want what happens on the mouse event to happen when on the enterFrame, but I'm getting an Argument Error


ActionScript Code:
scrollButton.addEventListener(MouseEvent.CLICK, _scroll);
this.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
function _scroll(evt:MouseEvent):void {
    this.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}

What can I do to "trigger" this mouse event to start onEnterFrame?

Thanks
Tara

Use Of OnEnterFrame
Does extensive use of onEnterFrame degrades the performance of flash.

OnEnterFrame
I have a fla that has 6 audio files that play at various frames. I also have a simple button that only turns the audio off (does not toggle, just off). I want to continually check to see if the soundOff variable has been changed to true (thus turning off the sound). Here is what I have:


ActionScript Code:
//set sound to on
var soundOff = false;
trace("soundOff = "+soundOff);

//define callback for button
audioOff_btn.onRelease = function() {
    _level0.soundOff = true;    //stops future sounds
    this._alpha = 70;
    stopAllSounds();    //stops current sound
    trace("button pushed and soundOff = "+soundOff);
};

//check var
onEnterFrame = function () {
    if (soundOff == true) {
        stopAllSounds();
        trace("check the soundOff var; it is set to "+soundOff);
        delete onEnterFrame();
    }
};

And I get this error:


Quote:




256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.




Should this work in the place of the onEnterFrame? But I get unpredictable results with:

ActionScript Code:
while (soundOff == true)
stopAllSounds();

I would like all the code to only be placed once, I am able to get it to function without the onEnterFrame if I place this on every frame that has a sound clip, but that seems very silly and poor OOP.


ActionScript Code:
//check var at each sound point
if (soundOff == true) {
    stopAllSounds();
    trace("check the soundOff var; it is set to "+soundOff);
}

Thanks!

OnEnterFrame
Hello
I am loading a swf file into a Movieclip on a button action, and a want to fade in and move this Movieclip(from top right to center) when the button is clicked. I have tried using onEnterFrame but can`t get it to work. Can anyone help me please...........

this.mcDropin._alpha=0;
this.map.name1900.onRelease = function() {
loadMovie("extmovie.swf",mcDropin);
_root.mcDropin.onEnterFrame= function() {
this._alpha += 5;
if(this._alpha >=100){
this.onEnterFrame=false;
}
}
}

OnEnterFrame
i have an animation that plays inside a movie clip on the main timeline, at a certain point i have put an onEnterFrame function to check and see if the _root timeline has advanced beyond 2, to resume playing... its not working though..







Attach Code

onEnterFrame = function(){ //this in on frame 197
if(_root._currentframe >= 3){
gotoAndPlay(199);
}
}

// i have gotoAndPlay(197); on frame 198

OnEnterFrame
Is "onEnterFrame" being taken as a listener? I guess everyting which is "on(Something)" is a listener isn't it? And also, is there another use for this action apart from a stage which has only one frame (i.e. onEnterFrame only invokes an action whenever the timeline hits the this particular frame so therefore there is no point placing onEnterFrame on 10th frame of a timeline because the code underneath would happen anyway..)

...sorry I was just having an argument with my mate.

Thanks

OnEnterFrame
I have a basic question about the onEnterFrame event handler. I understand how this code will continually repeat the output trace text:

onEnterFrame = function () {
trace ("onEnterFrame called");
}

but why does this only output the trace text once and stop:

onEnterFrame = RepeatFN()

function RepeatFN() {
trace ("onEnterFrame called");
}

Copyright © 2005-08 www.BigResource.com, All rights reserved