OnEnterFrame Function Location
Hi all,
The following code works fine:
ActionScript Code: function SomeCalledFunction (){ onEnterFrame = function() { trace("Hello"); }}
However, I wanted to make it a bit neater by defining the onEnterFrame function in a non-nested fashion. So I tried this:
ActionScript Code: function MyFrameFunction (){ trace("Hello");} function SomeCalledFunction (){ onEnterFrame = MyFrameFunction()}
It doesn'a work Can you do it this way? Or am I getting the syntax wrong somehow?
Ultrashock Forums > Flash > Flash Newbie
Posted on: 2005-08-16
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Delegate A Function To Another Location
ok guys I've a function in a class file I need to be located on the maintimeline of a movie,
I was trying to do sometihng like this:
l_module.getStatus = Delegate.create(this, function ():Status
{
return currentStatus;
});
so inside l_module (which is a movieClip) I would like to call getStatus() but it can't find it.
Is this right? Can it be done? F8 by the way!
Mouse Location To Function
Hi there.
I want to run a function everytime the mouse y is smaller than 150
How can I do this in AS3 ?
Specifying Exact Location With The LoadMovie Function
Hi
I'm trying to work out how to specify a precise location on the X and Y axis (basically the screen center) when using the loadMovieNum function.
My loaded movie is smaller in dimension than the main movie, and is currently loading in the top left corner of the screen. Is there are way of specifying a location?
(Using loadMovie/ 'Target' in a movie holder is not what we're looking for)
Any ideas would be greatly appreciated.
Cheers
Rob
OnEnterFrame=function()
We have a project that begins with a script. We create an emptyMovieClip “Ver” and “Pelicula”. Then charge on it “empresa.jpg” and it enters with a Fade_In function effect.
In the other part of the scenary we have a button with dynamic text into a movie clip.
When I press the button, the picture change, put de alpha value, but it doesn’t execute FadeIn function. Here is the code of the scrip that works ok, the code of de button that doesn’t work, is in bold characters.
I think that the problem is in the previous instruction ver.onEnterFrame=function(), but I don’t know what is the way to resolve it.
If somebody have any comment about it, we appreciate. Thanks.
This is a Script
createEmptyMovieClip("ver", 10);
ver.createEmptyMovieClip("pelicula", 100);
ver.pelicula.loadMovie("empresa.jpg");
ver._alpha=10;
ver.onEnterFrame=function(){
func_FadeIn(ver);
}
// Función de fadeIn
function func_FadeIn(mc) {
if (mc._alpha >=100)delete mc.onEnterFrame;
mc._alpha +=5;
};
This is a Button into a MovieClip
on (release) {
loadMovie("producto.jpg", "_level0.ver.pelicula");
ver._alpha=10;
ver.onEnterFrame=function(){
func_FadeIn(ver);
}
}
Add A Function To A MC's OnEnterFrame?
Hey,
I want an object to call an function as an enterFrame event, but that function will work like that for all the objects.
i.e.:
code:
function move(){
this._x += 40;
}
this.objectOne.onEnterFrame = function(){
move();
}
this.objectTwo.onEnterFrame = function(){
move();
}
Object One and object Two will now move 40 pixels on every enterFrame event.
I know you can do this another way round, but I need it like this, only then it should work
How could I do it?
SaphuA
OnEnterFrame=function() ?
onEnterFrame=function() {
XXX
}
Hi, I use the above function to loop my appliation. But if I have completed my task and want it not to loop anymore, and to break off from this function.
How can this be done? Anyone can help me?? Thanks alot..
Alvin
-----
[F8] Where Would I Put The OnEnterFrame Function?
Hey all,
I am controlling a movieclips' properties with some buttons. I'd like to just keep a button pressed down and it continuously change, but at current time...I have to keep pressing the button.
I know it needs the onEnterFrame function, but anytime I put it anywhere...it does not work.
Here is the file:
http://ata.saic.com/media/aj/buttons%20navigation.fla
Code:
code:
var leftUp_mc:MovieClip;
var leftRight_mc:MovieClip;
var leftDown_mc:MovieClip;
var leftLeft_mc:MovieClip;
var middleUp_mc:MovieClip;
var middleRight_mc:MovieClip;
var middleDown_mc:MovieClip;
var middleLeft_mc:MovieClip;
var rightUp_mc:MovieClip;
var rightRight_mc:MovieClip;
var rightDown_mc:MovieClip;
var rightLeft_mc:MovieClip;
var switchLeft_mc:MovieClip;
var switchRight_mc:MovieClip;
function buttons(p_message, p_button, frameLabel)
{
p_button.onPress = function()
{
//trace(p_message);
joystick_mc.gotoAndStop(frameLabel);
if(p_button == leftRight_mc)
{
image_mc._x +=1;
}
if(p_button == leftLeft_mc)
{
image_mc._x -=1;
}
if(p_button == leftUp_mc)
{
image_mc._y -=1;
}
if(p_button == leftDown_mc)
{
image_mc._y +=1;
}
if(p_button == rightUp_mc)
{
image_mc._xscale -=1;
image_mc._yscale -=1;
}
if(p_button == rightDown_mc)
{
image_mc._xscale +=1;
image_mc._yscale +=1;
}
}
p_button.onRelease = function()
{
joystick_mc.gotoAndStop(1);
}
}
buttons(":: leftUp pressed ::", leftUp_mc, 5);
buttons(":: leftRight pressed ::", leftRight_mc, 4);
buttons(":: leftDown pressed ::", leftDown_mc, 2);
buttons(":: leftLeft pressed ::", leftLeft_mc, 3);
buttons(":: middleUp pressed ::", middleUp_mc, 9);
buttons(":: middleRight pressed ::", middleRight_mc, 8);
buttons(":: middleDown pressed ::", middleDown_mc, 6);
buttons(":: middleLeft pressed ::", middleLeft_mc, 7);
buttons(":: rightUp pressed ::", rightUp_mc, 13);
buttons(":: rightRight pressed ::", rightRight_mc, 12);
buttons(":: rightDown pressed ::", rightDown_mc, 10);
buttons(":: rightLeft pressed ::", rightLeft_mc, 11);
buttons(":: leftSwitch pressed ::", switchLeft_mc, 14);
buttons(":: rightSwitch pressed ::", switchRight_mc, 15);
Any help would be appreciated.
Thanks in advance!
OnEnterFrame Function Help
Can someone help with my code, I want my movieclip to load in my emptyClip when on the first frame.
ActionScript Code:
onEnterFrame= function{
_root.mcEmptyClip03.attachMovie('movHeader','mcHeader',1);
};
This OnEnterFrame Function
Hi,
I have a snippet of actionscript that I use in a bunch of frames (obvious candidate for a function). The problem is I'm not really sure how to create a function when all my code is within an onEnterFrame function itself.
Can anyone give me the basics on how to create say a hover_function(enter button id here); ?
Thanks!
Here is my code:
Attach Code
this.onEnterFrame=function(){
if(this.hover==true & this.border_grow._currentframe<this.border_grow._totalframes & _global.active!=this.ival){
this.border_grow.gotoAndStop(this.border_grow._currentframe+1);
this.hovercycle=false;
if(this.thmb._alpha>50){
this.thmb._alpha-=2;
}
}
else if(this.hovercycle==false & this.border_grow._currentframe>1){
this.border_grow.gotoAndStop(this.border_grow._currentframe+1);
if(this.thmb._alpha>50){
this.thmb._alpha-=2;
}
}
//This reverses the hover cycle
if(this.hover!=true & _global.active!=this.ival & this.hovercycle==true){
this.border_grow.gotoAndStop(this.border_grow._currentframe-1);
}
//this will tell if it has already gone to the end of the hover
if(this.border_grow._currentframe==this.border_grow._totalframes & this.hover!=true & _global.active!=this.ival){
this.hovercycle=true;
}
if(_global.active==this.ival){
if(this.border_grow._currentframe<this.border_grow._totalframes){
this.border_grow.gotoAndStop(this.border_grow._currentframe+1);
}
if(this.thmb._alpha>25){
this.thmb._alpha-=3;
}
}
//this.border_grow.is_active._alpha=0;
else if(this.thmb._alpha<100 & this.hovercycle!=false){
this.thmb._alpha+=2;
}
}
Edited: 11/27/2007 at 04:01:14 PM by PKENGLISH
Function, OnEnterFrame
This builds a tsunami-like menu.
I was wondering, if it would be possible to write a function out of it and if possible also to delete the onEnterFrame on an appropriate time, in order to save performance.
PHP Code:
stop();centerx = Stage.width/2;centery = Stage.height/2;var menuholder = this.createEmptyMovieClip("menuholder", -1);menuholder._y = centery;menucount = 5;menuitems = [];miwidth = 50;miborder = 2;startx = centerx-((menucount-1)*(miwidth+miborder))/2;//trace(startx);for (var i = 0; i<menucount; i++) { var menuitem = this.menuholder.attachMovie("menuitem"+i, "menu"+i, i); menuitem._x = startx+i*(miwidth+miborder); menuitem.id = i; menuitem.onRollOver = function() { _root.selected = this; }; menuitems.push(menuitem);}onEnterFrame = function () { var width = 0; for (var i = 0; i<menucount; i++) { var xxm = menuitems[i]._xmouse; var yym = menuitems[i]._ymouse; var xm = Math.sqrt(xxm*xxm+yym*yym); if (xm<50) { menuitems[i]._xscale = menuitems[i]._yscale += ((200-xm)-menuitems[i]._yscale)/3; } else { menuitems[i]._xscale = menuitems[i]._yscale += (100-menuitems[i]._yscale)/3; } width += menuitems[i]._width; } width += (menucount-1)*miborder; var xpos = Math.round(centerx-width/2); for (var i = 0; i<menucount; i++) { if (i == 0) { xpos += miborder+menuitems[i]._width/2; menuitems[i]._x = xpos; } else { xpos += menuitems[i-1]._width/2+miborder+menuitems[i]._width/2; menuitems[i]._x = xpos; } }};
Where Would I Put The OnEnterFrame Function?
Hey all,
I am controlling a movieclips' properties with some buttons. I'd like to just keep a button pressed down and it continuously change, but at current time...I have to keep pressing the button.
I know it needs the onEnterFrame function, but anytime I put it anywhere...it does not work.
Here is the file:
http://ata.saic.com/media/aj/buttons%20navigation.fla
Any help would be appreciated.
Thanks in advance!
Function Location In Scope Chain And Speed
Hi,
Given a _root MovieClip that only contains this code.
Code:
stop();
function MyObject(id){
this.ID=id;
};
MyObject.prototype.ShowId(){
trace(this.ID);
};
function DoesNothing(){
};
var objA=new MyObject(12);
objA.ShowId();
When the line: objA.ShowId(); is executed where does Flash first look in the scope chain for the function ShowId()???
Does it first look in the Object??
Or does it first look in _root??
If there are say 5 functions like DoesNothing() all scoped to _root
what method is used to locate a function in the scope chain??? Is the scope chain searched in a linear fashion. And by what method is the correct function chosen .... by a comparison of function name????
Shipstern
OnEnterFrame Function With CreateEmptyMovieClip
I'm having trouble with this onEnterFrame function not executing, and I can't seem to figure out why... The code below is basically drawing a line, but i want it to fade out as it goes:
onClipEvent(load){
_root.segmentNum = 1;
prevX=_root._xmouse;
prevY=_root._ymouse;
}
onClipEvent(enterFrame){
createEmptyMovieClip("segment"+_root.segmentNum,_r oot.segmentNum);
with(this["segment"+_root.segmentNum]){
this._alpha=100;
moveTo(_root.prevX,_root.prevY);
lineStyle(4,0x00ff00,100);
x= _root._xmouse-_parent._x;
y=_root._ymouse-_parent._y;
lineTo(x,y);
this.onEnterFrame = function(){
_alpha-=1;
if (_alpha <0){
swapDepths(0);
removeMovieClip(this);
}//end if(_alpha <0)
}//end onEnterFrame
_root.prevX=x;
_root.prevY=y;
}
_root.segmentNum++;
}
Thanks
_root.onEnterFrame = Function() HELP
hi,
am using _root.onEnterFrame = function() to run some postion changes
and to get a timer going.. thing is i want the timer to start from 0
each time the function gets called as the function counts till 20
then does something else..if it carrys on the function wont work the
next time its passed... so basically is there any way of stopping the
enterframe function.. below is my code..
function back () {
if (_root.inPos == true) {
corn1.X = 87.25
corn1.Y = 52.5
corn2.X = 95.85
corn2.Y = 52.6
corn4.X = 95.85
corn4.Y = 60.85
corn3.X = 87.25
corn3.Y = 61
inPos = false;
_root.onEnterFrame = function() {
time = time+1;
if (time == 20) {
this.go()
}
}
}
}
anyone with any ideas ??
Delete This.onEnterframe Function?
To avoid unneccesary onEnterFrame checks I wonder if i can delete it after '} else {'. I dont want to removeMovieClip.
PHP Code:
onClipEvent(load) {
function expand(endSize) {
this.onEnterFrame = function () {
var myHeight = _height;
if(_height < endSize) {
myHeight = myHeight*1.2 + 1;
if(myHeight > endSize) {
myheight =endSize;
}
} else {
myheight =endSize;
}
_height = _parent.mask._height = myheight;
_parent.videoplayerbg._y = _parent.player._y = myheight + 7;
// delete the onEnterframe function?
}
}
}
Any thougts or cool tricks out there?
//pod
OnEnterFrame Function Question
Maybe someone can help me. Why is my component still shaking while var shaking is false? What do I have to change in the code?
PoliceClass.prototype.onEnterFrame = function() {
var shaking = false;
if (shaking = true) {
this._x = this._x - random(5) + (+ random(5));
this._y = this._y - random(5) + (+ random(5));
}
}
Regards,
Jorrit
Pausing OnEnterFrame Function
Hi, I need to pause an onEnterFrame function and then restart the same function using a separate button.
I have a movie clip with the onEnterFrame function within it and then I have a separate button that I used "delete rec_.onEnterFrame;" to stop the function. The problem I'm having is restarting the same function again.
If someone could help I would appreciate it.
Thanks.
OnEnterFrame Function Question
I've got this code that I use fairly frequently in flash:
code:
glow1.onEnterFrame = function() {
if (zoom1) {
this.nextFrame();
} else{
this.prevFrame();
}
};
It's for a button(movieclip) that when you enter the movieclip with your mouse, an image turns on, and when you move off the button the image turns off.(the perfect fade...learned from praystation) So when I have several buttons, I have to repeat this code, for every single button. When I get about thirty buttons, it seems pretty repetitive to have this code. So I want to make it usable for all the buttons with just one code/function. I'm not sure if that requires a for loop, or an array or what. but here is what i've been struggling on below, though it doesn't work. If you could help me on what I'm doing wrong it would be greatly appreciated. Thank you!
code:
mainArray = new Array(8);
for(i=0; i<8; i++) {
mainArray[i] = new Array(8);
mainArray[i] = "[" + i + "]";
}
//i'm not sure what this part does, so i've commented it out
//outerArraylength = mainArray.length;
//for(i=0; i < outerArraylength; i++) {
trace(mainArray);
//}
for (i=0;i<8;i++) {
_root["glow"+i].onEnterFrame = function() {
if (_root["zoom"+i]) {
_root["glow"+i].nextFrame();
} else{
_root["glow"+i].prevFrame();
}
};
}
SetInterval With OnEnterFrame Function?
this.objectMc.shake = function() {
clearInterval(shakeStart)
trace("shake")
this.onEnterFrame = function() {
trace("something")
};
}
this.objectMc.pressed = function() {
this.onPress = function() {
startDrag(this, false, 50, 300, 350, 1000);
shakeStart=setInterval(objectMc.shake,1000)
};
};
When I press my object, I see "shake" in my output window, but I don't see "something"... It seems like the enterFrame function was deleted by the setInterval !!!
This is quiet basic I think... but How can I fix this problem???
Thank U
Call Function Within A OnEnterFrame
peepz,
i want to call a funtion once within a onEnterFrame, butthe problem is that the onEnterFrame needs to go on and execute the function only once...(if its between the desired x positions (see script below))
my code
code:
onClipEvent(enterFrame)
{
if(this._x < -150 && this._x > -1600)
{
//execute once!
fadeIn()
}
else{
//execute once!
fadeOut()
}
this._x = (this._parent.mcBG._x * 1.4)-1950
this._y = (this._parent.mcBG._y * 1.8)-160
}
hope u can help..
thanks already!
OnEnterFrame = Function() [with Loop]
ok im trying to give a funtion to the following MC's lwall1, lwall2, lwall3 ....ect
(also rwall1, ...ect) and here is the script im using to give them all the function
PHP Code:
onClipEvent(load) {
for (i=1;i<=50;i++) {
this["lwall"+i].onEnterFrame = function () {
if (this.hitTest(_root.main.lefthit)) {
_root.main.mleft = 0;
cclear = 1;
}
if (!this.hitTest(_root.main.lefthit) && cclear == 1) {
_root.main.mleft = 1;
cclear = 0;
}
}
}
for (i=1;i<=50;i++) {
_root.level["rwall"+i].onEnterFrame = function() {
if (this.hitTest(_root.main.righthit)) {
_root.main.mright = 0;
cclear = 1;
}
if (!this.hitTest(_root.main.righthit) && cclear == 1) {
_root.main.mright = 1;
cclear = 0;
}
}
}
}
When i looked at the Debug mode, instead of giving each movieclip the function it should, it sets a variable inside the MC called onEnterFrame, and then the rest of the code is just lost i guess o.0
Recalling An OnEnterFrame Function?
ok so i have some code that is like
Code:
onEnterFrame = function() {
//my game
}
Now, when a part of the game finishes, it stops everything so it stops the onEnterFrame function with
Code:
onEnterFrame = null;
Now if i wanted to start up my game again, how do i recall the onEnterFrame command?
[F8] Deleting An OnEnterFrame Function
How do I go about deleting an OnEnterFrame Function after it's completed it's task, since it's just going to loop forever and ever.
Does that also chew up your memory if it's not removed?
[CS3] OnEnterFrame Within Function Error?
Hey,
I'm using Flash CS3 professional.
Code:
_root.createEmptyMovieClip("myMC",1);
myFunction = function () {
// do some initial stuff
_root.myMC.onEnterFrame = function() {
// do stuff again... and again.... and again...
}
};
myFunction();
that code comes up with the following error when i try to autoformat:
Error with autoformat near line: _root.myMC.onEnterFrame = function() {
Is the way i'm doing it bad practice? What's going on?! Everything checks out OK in the code checker.
Cheers
OnPress And OnEnterFrame Function
Hello
I am trying to continuesly move objects across the screen and then when the user presses on the object it moves to the center of the screen and enlarges. I can get the onPress to work, but when I add the onEnterFrame the onPress stops working. I might be going at this from the wrong angle. Any help would be great!
PHP Code:
import mx.transitions.Tween;
import mx.transitions.easing.Regular;
indiaMC.onEnterFrame = function(){
moveObject(this);
}
indiaMC.onPress = function(){
pickCountry(this);
}
function moveObject (mc){
onEnterFrame = function (){
if (mc._x > -100){
mc._x = mc._x - 5;
} else{
setProperty(mc, _x, 900);
}
}
}
function pickCountry (mc){
onEnterFrame = function(){
var moveToCenterX:Tween = new Tween(mc, "_x", Regular.easeOut, mc._x, 400, 1, true);
var moveToCenterY:Tween = new Tween(mc, "_y", Regular.easeOut, mc._y, 300, 1, true);
var enlargeCountryX:Tween = new Tween(mc, "_xscale", Regular.easeOut, mc._xscale, 600, 1, true);
var enlargeCountryY:Tween = new Tween(mc, "_yscale", Regular.easeOut, mc._yscale, 400, 1, true);
}
}
Specify OnEnterFrame Function Within A Class
I saw a thread about onEnterFrameBeacon, but all I want to be able to do is specify onEnterFrame function within a class, very tidy no ?
But no It just wont work, despite my having seen many examples of this online?
I wonder if it is my Flash ide?- but doubtfull.
i want to do
-------------inside class---------------------
private function onEnterFrame(){
trace("it worked");
}
OnEnterFrame Function Not Being Triggered
I have a ease function that is suppose to move an object to a specific location onEnter Frame but it is not being triggered. is there someting I am missing in my code.
Code:
/////////////////////////////
var easing = 0.2;
var targX = -10;
var targY = 250;
/////////////////////////////
namesArray = new Array("bg", "widget1", "widget2", "widget3", "MainLogo", "MainMessage");
locationsArray = new Array([0, 0], [-500, 250], [275, 225], [445, 250], [530, 105], [410, 23]);
for (i=0; i<namesArray.length; i++) {
container_mc.createEmptyMovieClip(namesArray[i]+"_mc", i);
container_mc[namesArray[i]+"_mc"]._x = locationsArray[i][0];
container_mc[namesArray[i]+"_mc"]._y = locationsArray[i][1];
if (i == 0) {
container_mc[namesArray[i]+"_mc"].loadMovie("images/"+namesArray[i]+".jpg");
} else {
container_mc[namesArray[i]+"_mc"].loadMovie("images/"+namesArray[i]+".swf");
}
}
//////////////////////////////
container_mc.widget1_mc.onEnterFrame = ease;
function ease() {
var dx = targX-this._x;
var dy = targY-this._y;
if (Math.abs(dx)<1) {
this._x = targX;
this._y = targY;
delete onEnterFrame;
trace("done");
} else {
var vx = dx*easing;
var vy = dy*easing;
this._x += vx;
this._y += vy;
}
}
//////////////////////////////
How To Play Again Function OnEnterFrame
When I press button, variable a is growing to value "50". After this I delete this.onEnterFrame. How to run this.onEnterFrame = function() when I press some button again ?
ActionScript Code:
a = 0;
this.onEnterFrame = function() {
a += b;
trace(a);
if (a == 50) {
delete this.onEnterFrame;
}
};
my_but1.onRelease = function() {
a = 0;
b = 1;
};
my_but2.onRelease = function() {
a = 0;
b = 2;
};
Modifying OnEnterFrame Function
I don't want my AS - generated object to respond when the mouse enters the complete document, but rather in a small square that is situated in the middle of the flash document.
Let's say xa = 100 to xb = 150 and ya = 100 and yb = 150.
Can this be achieved with the onEnterFrame - function? If yes, how do you do it?
Made Up Function? OnEnterFrame (x) {}
Howdy, I am searching for something that will help me but I'd thought I'd post the questions in the meantime:
I have a 50 frame movie. As it progresses through every frame I want it to increment a variable for use in a frame-by-frame movement of an mc instance. Something like this (pseudo-pseudo code ):
///////////////////////////////////////////
x=1;
if (thisFrame = x) {
onNextFrame(x);
}
function onNextFrame(frameNum) {
myMC._x = 10*frameNum;
x++;
}
///////////////////////////////////////
I know it seems convuluted a bit but I am just curious as to the approach in general and not specifically replotting x/y positions etc. Of course, I want to write one script on frame 1 that will persist throughout the 50 frames. I could just write a frame script for every frame I suppose
Thanks,
Cheez
OnEnterFrame Function Seems Broken
I am attempting to set the onLoad and onEnterFrame properties from actionscript code. It seems to work to a certain point.
Here's the basics. The following code is in the first frame of a "parent" MC which then creates 6 empty MC's. It sets each MC's onload property to a function called crScene and the onEnterFrame property to a function called animScene.
Here's what's in the parent MC...
PHP Code:
var nShapes = 6;
var aShapes = new Array(nShapes);
for (var i=0; i<nShapes; i++) {
aShapes[i] = this.createEmptyMovieClip("shape_"+i, (i+20));
aShapes[i].onLoad = crScene(aShapes[i], ShpArray, lParams, -(i*10));
aShapes[i].onEnterFrame = animScene(aShapes[i]);
}
stop();
The onload function draws a shape on each respective mc ( aShapes[0..6] so to speak ) and works great.
Here's the full animScene function right now as a test.
PHP Code:
MovieClip.prototype.animScene = function(mc) {
mc._y += 10;
}
This works one time then stops. Maybe I'm forgetting something, but shouldn't this loop and continue adding 10 to the _y property each time, causing the MC to slowly move up the page ????
I haven't told it to stop executing ??
Any help would be great
Regards,
Dan
Killing An OnEnterFrame Function
Howcan I terminate an onEnterFrame function?
I have a preloader that checks the progress of some dynamic images loading in and I need to determine when the file is loaded and then make the onEnterFrame function stop checking the whole time...
Call Function Within A OnEnterFrame
peepz,
i want to call a funtion once within a onEnterFrame, butthe problem is that the onEnterFrame needs to go on and execute the function only once...(if its between the desired x positions (see script below))
my code
ActionScript Code:
onClipEvent(enterFrame)
{
if(this._x < -150 && this._x > -1600)
{
//execute once!
fadeIn()
}
else{
//execute once!
fadeOut()
}
this._x = (this._parent.mcBG._x * 1.4)-1950
this._y = (this._parent.mcBG._y * 1.8)-160
}
hope u can help..
thanks already!
OnEnterFrame = Function Within A Class
Hi all
I've created a class that has a method that receives an XML node. Currently, it uses a for loop to go throught the XML, like this:
for(var i=0; i<=(myXML.childNodes.length-1);i++){
// Internal Actions
}
Now this would work fine if the XML node received by this method has 10 nodes, 20 nodes, and so on. But I'll need this to handle anywhere from 1000 to 2000 nodes.
If I were writing this code on the timeline, I would use an onEnterFrame action to drill through a 2000 node XML, like this:
var i=0;
this.onEnterFrame = function(){
if(i<=(myXML.childNodes.length-1)){
// Internal Actions
i++;
}else{
this.onEnterFrame = null;
}
}
But I want to do something like this within a class. But every attempt to use the above onEnterFrame in a class hasn't worked. Nothing within the onEnterFrame ever gets called.
I'm still a bit fuzzy how to write classes so any help is appreciated.
Thanks
Chris
OnEnterFrame From A Prototype Function
The function is called on release of a movieclip. I'm making a drag a
drop navigation and there are two content windows .. "h1" and "h3".
I don't think there's anything(much) wrong with my code itself, I'm
just having trouble with calling anything within h_ins.onEnterFrame.
Is there a fundamental issue that I'm not aware of? Below are all the
details if you're interested.
PHP Code:
if(this._droptarget.substr(0,3) == "/h1" || this._droptarget.substr(0,3) == "/h3") { var n; if(this._droptarget.substr(0,3) == "/h1") { n = 1; } if(this._droptarget.substr(0,3) == "/h3") { n = 3; } loadCon(n,"sub11.swf"); }
Now here's the function called...
I have previous javascript knowledge just so you know where I'm coming
from...
PHP Code:
MovieClip.prototype.loadCon = function(n, file) { hcon = eval("_root.h"+ n +".h"+ n +"con"); hcon._alpha = 0; hcon.loadMovie(file); this.createEmptyMovieClip("h_ins",92); h_ins.onEnterFrame = function() { hcon = eval("_root.h"+ n +".h"+ n +"con"); hmask = eval("_root.h"+ n +".h"+ n +"conMask"); hlbar = eval("_root.h"+ n +".h"+ n +"loadBar"); hltext = eval("_root.h"+ n +".h"+ n +"loadText"); th = hcon.getBytesTotal(); lh = hcon.getBytesLoaded(); percenth = Math.round((lh/th)*100); //hlbar is a standard solid shape for the preloader hlbar._visible = 1; hlbar._xscale = percenth; //hltext is a movieclip with a dynamic text field within hltext.loadText.text = percenth+" %"; if (hcon._width > 0 && th == lh) { hlbar._xscale = 0; hltext.loadText.text = ""; hcon.setMask(hmask); hcon.fadeIn(5,100); delete h_ins.onEnterFrame; } } }
The problem is, it's not even calling h_ins.onEnterFrame once .. why
is that?
The movie loads fine if I set the _alpha to 100, but I need the
preloader to check wheather it's fully loaded and wheather or not I
can apply the mask to it.
Thanks for your time, and hopefully thanks for your help.
Delete Function OnEnterframe - Help?
Hi,
I have a function which starts on one frame, but I'd like it to stop on the following frame - how do I do that??
I've tried doing it by setting a variable and using an 'if' statement to stop it once the variable has changed...but it's not working
I'm not very good with if's and else if's - can anyone help?? I have a bar which remains on stage at all times and pages are loaded into level1. On one of my pages, the bar sticks to _ymouse, but I need it to stop doing that when I exit the page. Can anyone help?? Here's what I've got so far...don't laugh - it kinda works...
_level0.barMC.onEnterFrame = function() {
this.onMouseMove = function () {
var yMouse = _root._ymouse;
if(stick = false){
delete this.onEnterFrame;
}
if(Math.abs(yMouse - this._y) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 6;
}
if(_level0.barMC._y<59){
_level0.barMC._y = 59;
}
}
};
Many thanks in advance!!!
Call Function Within A OnEnterFrame
peepz,
i want to call a funtion once within a onEnterFrame, butthe problem is that the onEnterFrame needs to go on and execute the function only once...(if its between the desired x positions (see script below))
my code
ActionScript Code:
onClipEvent(enterFrame){ if(this._x < -150 && this._x > -1600) { //execute once! fadeIn() } else{ //execute once! fadeOut() } this._x = (this._parent.mcBG._x * 1.4)-1950 this._y = (this._parent.mcBG._y * 1.8)-160}
hope u can help..
thanks already!
How To Cancelling This.onEnterFrame = Function
this.onRelease = function() {
this._x = (this._x+500);
_parent.InArrow._x = (_parent.InArrow._x-300);
this.onEnterFrame = function() {
_root.prevFrame();
};
};
Please bear with me, im new at all this!
this is the actionscript i have on a button nested within a couple of movie clips.
_root.prevFrame makes my main timeline run back from frame 15 to frame 1. When the main time line hits 1 i need the
this.onEnterFrame = function() {
_root.prevFrame();
to be cancelled, but i can't work out how to do it.
all help much appreciated. Attached is the swf of where i am so far, it should give you a better idea of why i need this to be cancelled.
Replaying An OnEnterFrame Function?
Hey gang!
Got a piece of code that moves a line of text I'm calling "eeScroller". I'm using this method because timeline and as tweens make the movement herky jerky (when the movement is slow).
What I want to do is reset the _x of eeScroller to 0.9 once it reaches the _x of -889.3
Here's what I got so far:
Code:
function movething() {
_root.eeScroller.onEnterFrame = function() {
if (_root.eeScroller._x>=-889.3) {
_root.eeScroller._x += -.75;
}
};
}
movething();
And that moves the movie clip... just need the reset script!
I can't figure out how to implement onMotionFinished if that's even the way to do it...
Help!
Thanks!
OnEnterFrame From A Prototype Function
The function is called on release of a movieclip. I'm making a drag a
drop navigation and there are two content windows .. "h1" and "h3".
I don't think there's anything(much) wrong with my code itself, I'm
just having trouble with calling anything within h_ins.onEnterFrame.
Is there a fundamental issue that I'm not aware of? Below are all the
details if you're interested.
PHP Code:
if(this._droptarget.substr(0,3) == "/h1" || this._droptarget.substr(0,3) == "/h3") { var n; if(this._droptarget.substr(0,3) == "/h1") { n = 1; } if(this._droptarget.substr(0,3) == "/h3") { n = 3; } loadCon(n,"sub11.swf"); }
Now here's the function called...
I have previous javascript knowledge just so you know where I'm coming
from...
PHP Code:
MovieClip.prototype.loadCon = function(n, file) { hcon = eval("_root.h"+ n +".h"+ n +"con"); hcon._alpha = 0; hcon.loadMovie(file); this.createEmptyMovieClip("h_ins",92); h_ins.onEnterFrame = function() { hcon = eval("_root.h"+ n +".h"+ n +"con"); hmask = eval("_root.h"+ n +".h"+ n +"conMask"); hlbar = eval("_root.h"+ n +".h"+ n +"loadBar"); hltext = eval("_root.h"+ n +".h"+ n +"loadText"); th = hcon.getBytesTotal(); lh = hcon.getBytesLoaded(); percenth = Math.round((lh/th)*100); //hlbar is a standard solid shape for the preloader hlbar._visible = 1; hlbar._xscale = percenth; //hltext is a movieclip with a dynamic text field within hltext.loadText.text = percenth+" %"; if (hcon._width > 0 && th == lh) { hlbar._xscale = 0; hltext.loadText.text = ""; hcon.setMask(hmask); hcon.fadeIn(5,100); delete h_ins.onEnterFrame; } } }
The problem is, it's not even calling h_ins.onEnterFrame once .. why
is that?
The movie loads fine if I set the _alpha to 100, but I need the
preloader to check wheather it's fully loaded and wheather or not I
can apply the mask to it.
Thanks for your time, and hopefully thanks for your help.
Delete Function OnEnterframe - Help?
Hi,
I have a function which starts on one frame, but I'd like it to stop on the following frame - how do I do that??
I've tried doing it by setting a variable and using an 'if' statement to stop it once the variable has changed...but it's not working
I'm not very good with if's and else if's - can anyone help?? I have a bar which remains on stage at all times and pages are loaded into level1. On one of my pages, the bar sticks to _ymouse, but I need it to stop doing that when I exit the page. Can anyone help?? Here's what I've got so far...don't laugh - it kinda works...
_level0.barMC.onEnterFrame = function() {
this.onMouseMove = function () {
var yMouse = _root._ymouse;
if(stick = false){
delete this.onEnterFrame;
}
if(Math.abs(yMouse - this._y) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 6;
}
if(_level0.barMC._y<59){
_level0.barMC._y = 59;
}
}
};
Many thanks in advance!!!
AS1 - Calling OnEnterFrame Within Function
It's been a while since I had Flash open and I've got some serious rust going on.
I am attempting to run an onEnterFrame event from within another function and it just doesn't work for me. I can call the function that contains the onEnterFrame but the onEnterFrame never fires.
Please let me know if you can see any errors in my code below or where I might be going down the wrong path.
ActionScript Code:
//create 2 empty movie clips
this.createEmptyMovieClip("container1_mc", 0);
this.createEmptyMovieClip("container2_mc", 1);
//set global variable for clip being used
_global.current = "clip2";
//set alpha of clips
container1_mc._alpha = 100;
container2_mc._alpha = 100;
//TESTING** Check current clip
trace(_global.current);
//function to choose which clip to use
function chooseClip() {
if (_global.current != "clip1") {
trace("function1");
useOne();
} else if (_global.current != "clip2") {
trace("function2");
useTwo();
}
}
//function to fade up clip 1
function fadeUp1() {
container1_mc.onEnterFrame = function() {
trace("fading up");
this._alpha += 2;
if (this._alpha>=100) {
delete this.onEnterFrame;
}
};
trace("calling fade up 1");
}
//function to fade up clip 2
function fadeUp2() {
container2_mc._alpha = 50;
trace("calling fade up 2");
}
//function to load and swap depth clip 1
function useOne() {
trace("1 hit");
container1_mc.swapDepths(container2_mc);
container1_mc.loadMovie("img/test1.jpg");
_global.current = "clip1";
fadeUp1();
}
//function to load and swap depth clip 1
function useTwo() {
trace("2 hit");
container2_mc.swapDepths(container1_mc);
container2_mc.loadMovie("img/test3.jpg");
_global.current = "clip2";
fadeUp2();
}
stop();
Function fadeUp1() is where I am having the problem.
This code is located on Frame 1 along with 2 buttons that call the first function. The button code is:
ActionScript Code:
on (release) {
chooseClip();
}
Eventually, I will preload each jpeg being loaded but for now I just want to get them fading up.
Here is a link to my files.
Any help/advice would be appreciated.
Thanks in advance.
D
Why Not Do The Custom-function In OnEnterFrame
Last edited by hy01140 : 2004-12-17 at 21:58.
i have a custom-function of "movedMC",when it was set in onClipEvent(enterFrame)-function ,play exactily! but when it was set in onEnterFrame-function,don't play completely! I don't know why it's!
ActionScript Code:
onEnterFrame = function () {
trace("come in onEnterFrame"); //it's exactely
function mcMoved() {
trace("come in mcMoved");//it's out the gear
}
who can tell me why it?
And how do be solve it?
Calling Function With OnEnterFrame
Can someone explain why the following code works properly - calls the preload function repeatedly....
loadholder.onEnterFrame = function(){
checkPreload(_root.content);
}
... and this code doesn't:
loadholder.onEnterFrame = checkPreload(_root.content);
Thanks for your help.
How To Return A Value From OnEnterFrame Function?
Dear All,
I've already learn about onEnterFrame function...
I need to do so, but I've found that the value cannot pass from the function.
Here are my coding:
Code:
function GetSubCat() {
loadVariables("GetData.dat", this);
this.onEnterFrame = function() {
if (CountCat != undefined) {
SubCat = new Array();
for (j=1; j<=CountCat; j++) {
SubCat[j] = this["SubCat"+j];
}delete this.onEnterFrame;
}
};
return SubCat;
}
On the code above,
I've load some variables from the file: "GetData.dat" which contain CountCat, and SubCat1.... like
Code:
&CountCat = 3&
&SubCat1 = The first Cat&
&SubCat2 = The Second Cat&
&SubCat3 = The Third Cat&
I want to put all the SubCats to an Array.
And return the Array to the script.
for example:
SubCatArray = GetSubCat();
So that the SubCatArray (Array data type) can get the variables from the function.
can anyone help!?
Thanks a lot!
Obtaining 0::100 Numbers In OnEnterFrame Function
i wanted to obtain such numbers for changing _alpha property of the MC, the MC must disapear and apear slowly, otherwords alpha must change in such way: 0,1,2,3...100, 99,98,...1,0,1,2,...99,100.....
I was thinking and i found a solution..but i hope that there is one beter, cause here i use math functions..and cpu might be a little loaded.
here is the code:
_quality = "BEST";
square._alpha=0;
square.onEnterFrame=function(){
m=m+1;
n=n+0.07;
s=Math.abs(Math.sin(n))*100;
t=Math.abs(Math.sin(m))*100;
txt._alpha=s;
square._alpha=t;
//trace(s);
square._rotation=square._rotation+0.2;
//square._x=this._x+1;
_root.square._x = _root._xmouse;
_root.square._y = _root._ymouse;
//_root.txt._rotation=square._rotation;
_root.txt._x = _root._xmouse-40;
_root.txt._y = _root._ymouse-10;
}
i tried to use if (), but no wanted results, because square.onEnterFrame is a big cicle...
is there any other way to solve this? without math functions? maybe without square.onEnterFrame?
10x!
How To Delay An Action In OnEnterFrame Function.
Hi all,
Im still working on my platform game, for my last dat I hope i just need one little piece of code;
I got an onEnterFrame collision detecter. Now I got a function removeHard.
When my enemy hits my hero there is a variable "hit" that gets set to 1.
Now I have a function removeHard that removes one hard from my lives etc this fucntion works how its suppose to. Now what I need is as soon as the var hit = 1, the function removeHard gets called on once with a delay of lets say 1 second. The reason I need the delay for is becouse when I dont delay the character and the enemy move trough eachother and the function still gets called on repeadidly.
I hope someone can help me with this.
Thank you all in advance,
Grtz.
|