Stopping A ENTER_FRAME Function
How can I make a on ENTER_FRAME function from constantly running?Here is what I have Code: addEventListener(Event.ENTER_FRAME, onEnterFrame);private function onEnterFrame(event:Event):void { var speed:Number = 6; var ysize:Number = Tall - this.height; var xsize:Number = Wide - this.width; this.height += ysize / speed; this.width += xsize / speed; if (Math.abs (ysize) < 0.3 && Math.abs (xsize) < 0.3) { this.height = Math.abs (ysize); this.width = Math.abs (xsize); trace("done"); } } I know if I used the same thing in AS2 all I needed to do is delete this.onEnterFrame.Are there pre-defined classes in AS3 that would do the same thing.
KirupaForum > Flash > ActionScript 3.0
Posted on: 03-08-2008, 08:56 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Stopping ENTER_FRAME Motion
I have series of buttons that when clicked rotate a triangle object and begin to pulse. My problem is that I am having problems coming up with a way to stop the pulsing motion when another button is clicked. Currently when clicked the object does rotate and does pulse. When the next button is clicked it too rotates and pulses only the pulsing seems to multiply in pulsing speed. How can I resolve this problem.
Thanks.
Code attached
Attach Code
import fl.transitions.TweenEvent;
import fl.motion.easing.*
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.events.Event;
var myXML:XML = new XML();
var musicXML:XML = new XML();
var xmlLoader:URLLoader = new URLLoader();
var easing:Number = 0.2;
var channel:String = new String();
var thisButton:String = new String();
var thisImage:String = new String();
var imageLoader:Loader = new Loader();
var current=Number;
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance =5;
dropShadow.blurX=0;
dropShadow.blurY=75;
dropShadow.alpha=.6
dropShadow.angle=90;
dropShadow.color=0x03B5F7;
var angle:Number = 100;
var centerScale:Number =1;
var range:Number = .5;
var speed:Number = .5;
var xmotion:Number = 3;
var angle2:Number = 0;
var centerScale2:Number =0;
var range2:Number = 0;
var speed2:Number = 0;
var xmotion2:Number = 0;
xmlLoader.addEventListener(Event.COMPLETE, handleComplete);
xmlLoader.load(new URLRequest("radioText.xml"));
var top:header = new header();
top.x=0;
top.y=0;
addChild(top);
var bottom: lower = new lower();
bottom.x=0;
bottom.y=350;
addChild(bottom);
//////////////////////////////////////////////////////////
var genre:genreText = new genreText();
genre.x=420;
genre.y=75;
channel1(genre);
addChild(genre);
var genre2:genreText = new genreText();
genre2.x=420;
genre2.y=95;
channel2(genre2);
addChild(genre2);
var genre3:genreText = new genreText();
genre3.x=420;
genre3.y=115;
channel3(genre3);
addChild(genre3);
var genre4:genreText = new genreText();
genre4.x=420;
genre4.y=135;
channel4(genre4);
addChild(genre4);
var genre5:genreText = new genreText();
genre5.x=420;
genre5.y=155;
channel5(genre5);
addChild(genre5);
var genre6:genreText = new genreText();
genre6.x=420;
genre6.y=175;
channel6(genre6);
addChild(genre6);
var genre7:genreText = new genreText();
genre7.x=420;
genre7.y=195;
channel7(genre7);
addChild(genre7);
function loadImage(thisImage:String):void {
imageLoader.load(new URLRequest(thisImage));
imageLoader.x=15;
imageLoader.y=75;
addChild(imageLoader);
trace(thisImage);
}
function handleComplete(event:Event):void {
//Load in XML
myXML = new XML(event.target.data);
//ignore spaces
myXML.ignoreWhitespace;
trace("loaded");
top.filters = [dropShadow];
//Set the text boxes to proper data
genre.displayGenre_txt.text =myXML.theWham.musicType;
genre2.displayGenre_txt.text =myXML.justSpurs.musicType;
genre3.displayGenre_txt.text =myXML.discoFever.musicType;
genre4.displayGenre_txt.text =myXML.doggFather.musicType;
genre5.displayGenre_txt.text =myXML.topHits.musicType;
genre6.displayGenre_txt.text =myXML.punkNation.musicType;
genre7.displayGenre_txt.text =myXML.alternativeFuel.musicType;
thisImage =myXML.theWham.image;
loadImage(thisImage);
}
/*function active(): void {
if (current == 1){
pulse(genre);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
trace(current);
}else if(current == 2){
pulse(genre2);
stopPulse(genre);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
trace(current);
}else if(current == 3){
pulse(genre3);
stopPulse(genre2);
stopPulse(genre);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
trace(current);
}else if(current == 4){
pulse(genre4);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre7);
}
else if(current == 5){
pulse(genre5);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre);
stopPulse(genre6);
stopPulse(genre7);
}
else if(current == 6){
pulse(genre6);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre);
stopPulse(genre7);
}
else if(current == 7){
pulse(genre7);
stopPulse(genre2);
stopPulse(genre3);
stopPulse(genre4);
stopPulse(genre5);
stopPulse(genre6);
stopPulse(genre);
}
}*/
function pulse(channel):void {
channel.addEventListener(Event.ENTER_FRAME, pulse);
function pulse(event:Event):void {
channel.triangle_mc.scaleX = channel.triangle_mc.scaleY = centerScale + Math.sin(angle)*range;
angle += speed;
channel.triangle_mc.x= + xmotion;
}
}
/*function stopPulse(channel):void {
channel.addEventListener(Event.ENTER_FRAME, pulse);
function pulse(event:Event):void {
channel.triangle_mc.scaleX = channel.triangle_mc.scaleY = centerScale2 + Math.sin(angle2)*range2;
angle2 += speed2;
channel.triangle_mc.x= + xmotion2;
}
}*/
function rotate(channel): void {
var triRotate:Tween = new Tween(channel.triangle_mc,"rotation", Strong.easeOut, 0, 180, 1, true);
}
function channel1(channel):void{
channel.addEventListener(MouseEvent.CLICK, c1);
function c1(event:MouseEvent):void{
thisImage =myXML.theWham.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 1;
//active();
}
}
function channel2(channel):void{
channel.addEventListener(MouseEvent.CLICK, c2);
function c2(event:MouseEvent):void{
thisImage =myXML.justSpurs.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 2;
//active();
}
}
function channel3(channel):void{
channel.addEventListener(MouseEvent.CLICK, c3);
function c3(event:MouseEvent):void{
thisImage =myXML.discoFever.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 3;
//active();
}
}
function channel4(channel):void{
channel.addEventListener(MouseEvent.CLICK, c4);
function c4(event:MouseEvent):void{
thisImage =myXML.doggFather.image;
loadImage(thisImage);
rotate(channel);
//pulse(channel);
current = 4;
//active();
}
}
function channel5(channel):void{
channel.addEventListener(MouseEvent.CLICK, c5);
function c5(event:MouseEvent):void{
thisImage =myXML.topHits.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 5;
//active();
}
}
function channel6(channel):void{
channel.addEventListener(MouseEvent.CLICK, c6);
function c6(event:MouseEvent):void{
thisImage =myXML.punkNation.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 6;
//active();
}
}
function channel7(channel):void{
channel.addEventListener(MouseEvent.CLICK, c7);
function c7(event:MouseEvent):void{
thisImage =myXML.alternativeFuel.image;
loadImage(thisImage);
rotate(channel);
pulse(channel);
current = 7;
//active();
}
}
Pass Event.currentTarget On To Another ENTER_FRAME Function
i've got a function associated with a mouse event listener with one clip which sets the x and y of another clip (here it's 'myClip') as well as specifying the ENTER_FRAME function for that clip:
Code:
function mcOver(event:MouseEvent):void{
myClip.x = event.currentTarget.x;
myClip.y = event.currentTarget.y;
myClip.addEventListener(Event.ENTER_FRAME, moveClip);
}
then i have a function that i want to use for the ENTER_FRAME function which will cause the second clip ('myClip' again) to continue to follow the clip targeted with the mcOver function above:
Code:
function moveClip(){
myClip.x = ??? // need to target the event.currentTarget of the 'mcOver' function above
myClip.y = ??? // ditto.
}
I'm not sure how to target the currentTarget of that first mouse event within the enter frame function... I know there was a delegate method/class in AS2... how can i do this in AS3???
thanks for any help!
One ENTER_FRAME Function Used By Multiple Instances: Possible Without External Class?
I have a piece of code that is very similar to this example I found on LiveDocs, which I'm pasting here for convenience:
Code:
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
// draw a circle and add it to the display list
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0x990000);
circle.graphics.drawCircle(50, 50, 50);
circle.graphics.endFill();
addChild(circle);
// When this animation starts, this function is called every frame.
// The change made by this function (updated to the screen every
// frame) is what causes the animation to occur.
function fadeCircle(event:Event):void
{
circle.alpha -= .05;
if (circle.alpha <= 0)
{
circle.removeEventListener(Event.ENTER_FRAME, fadeCircle);
}
}
function startAnimation(event:MouseEvent):void
{
circle.addEventListener(Event.ENTER_FRAME, fadeCircle);
}
circle.addEventListener(MouseEvent.CLICK, startAnimation);
I understand how this works and it's a fine solution if you only have one clip named "circle" on the stage. However, let's say I have 10 circle clips on the stage named circle1, circle2, circle3, etc. Is there a way to use the same fadeCircle function to perform the same fading effect when any of the 10 circles are clicked? I'm guessing that this is why people build custom classes--so that every instance of the circle clip you add to the stage has the fading functionality "built in". But is there some way of doing this without having to create an external class file? I've already done something like this with more basic mouse events using event.currentTarget in the path instead of an instance name reference, like so:
Code:
function circleOver(event:MouseEvent):void {
event.currentTarget.x += 20;
}
for (var i:int=0; i<10; i++) {
circle[i].addEventListener(MouseEvent.MOUSE_OVER, circleOver);
}
I can't use event.currentTarget in the more complex example above because I don't know how to pass the instance name of the circle that was clicked to the function that fades the circle...if that's even possible.
I really like keeping all my script on the first frame of the timeline for now...it's just easier for me to wrap my head around until I get more comfortable with AS 3.0. Is there any way (without using an external class) to make each of the 10 circles capable of fading when clicked without having to write 10 similar fadeCircle functions? Isn't there some way to pass the name of the circle that was clicked to the generic fadeCircle function, then use that parameter in the path that makes the circle fade? Is my only option to write the fading code inside the timeline of the circle clip itself?
Thanks in advance!
Stopping Function
Hi all!
Can anybody tell me how to stop this function when entering Frame 2?
This code is on frame 1:
-----code
function one(pAnzahl, pBreite, pHoehe,pFlockenDim,pFlockenDichte) {
for (var i = 0; i<=pAnzahl; i++) {
this.attachMovie("fClip", "flocke"+i, i);
this["flocke"+i].skal = 50+(Math.random()*pFlockenDim);
this["flocke"+i].alpha = 20+(Math.random()*pFlockenDichte);
this["flocke"+i]._xscale = this["flocke"+i].skal;
this["flocke"+i]._yscale = this["flocke"+i].skal;
this["flocke"+i]._alpha = this["flocke"+i].alpha;
this["flocke"+i].xpos = this["flocke"+i]._x;
this["flocke"+i]._x = -10+(Math.random()*pBreite);
this["flocke"+i].zufall = 1+(Math.random()*2);
this["flocke"+i]._y = -10+(Math.random()*pHoehe);
this["flocke"+i].wind = -Math.PI+(Math.random()*Math.PI);
this["flocke"+i].onEnterFrame = function() {
this.rad += ((this.wind/180)*Math.PI);
this._x -= Math.cos(this.rad);
this._y += this.zufall;
if (this._y>=pHoehe) {
this._y = -5;
}
if ((this._x>=pBreite) || (this._x<=0)) {
this._x = -10+(Math.random()*pBreite);
}
};
}
}
// calling function
one(100,Stage.width,Stage.height,100,50);
-----/code
Thank you
Cheers
-----va
[F8] Stopping With A Function
OK so I have a function with an "if" statement that is be called and I believe it is function correctly except for the "if" part (in which the time line is supposed to stop).
Also the second function is being called an almost works correctly. It is supposed to play each "in" only once before it goes on to the next but it plays twice before it goes to the next. any ideas why?
my code is:
var swapNum:Number = 0
function swapNumber() {
if(swapNum<3) {
stop();
var nInterval = setInterval(Play, 3000);
function Play() {
clearInterval(nInterval);
gotoAndPlay(_currentframe+1);
swapNum++;
}
} else {
stop();
}
}
function textPlay() {
if (swapNum==0) {
_root.text_.gotoAndPlay("in 1");
} else if(swapNum==1) {
_root.text_.gotoAndPlay("in 2");
} else {
_root.text_.gotoAndPlay("in 3");
}
}
Stopping With A Function?
OK so I have a function with an "if" statement that is be called and I believe it is function correctly except for the "if" part (in which the time line is supposed to stop).
Also the second function is being called an almost works correctly. It is supposed to play each "in" only once before it goes on to the next but it plays twice before it goes to the next. any ideas why?
my code is:
var swapNum:Number = 0
function swapNumber() {
if(swapNum<3) {
stop();
var nInterval = setInterval(Play, 3000);
function Play() {
clearInterval(nInterval);
gotoAndPlay(_currentframe+1);
swapNum++;
}
} else {
stop();
}
}
function textPlay() {
if (swapNum==0) {
_root.text_.gotoAndPlay("in 1");
} else if(swapNum==1) {
_root.text_.gotoAndPlay("in 2");
} else {
_root.text_.gotoAndPlay("in 3");
}
}
Stopping A Function
I have the following code on the last frame of a movie clip. How do I put a stop to the function after I am done using it?
onEnterFrame = function () {
if (_global.x_pos>131 && _global.x_pos<258) {
} else {
_root.navigation.brandNav.brandDrop.rewinds.gotoAn dPlay(2);
}
if (_global.y_pos>76 && _global.y_pos<353) {
} else {
_root.navigation.brandNav.brandDrop.rewinds.gotoAn dPlay(2);
}
};
stop();
Stopping A Function
Is there any way to stop a function?
I have an event listener that is a function "onRollover1".
I have a second event listener that is a function "onStageLeave1".
Is there a way to put some code into the "onStageLeave1" function, to stop the "onRollover1" function?
In flash 9 there was no problem if the "onRollover1" function didn't complete before the "onStageLeave1" function started. The code worked fine. But ever since upgrading to CS3, there is a glitch, in which causes undesirable effects. http://demo.xennsoft.com/assets/menu.html Any help would be great! Thanks in advance :)
Edited: 12/17/2007 at 09:36:35 AM by djonesxenn
Stopping A Function
i have a snow effect in a movie with the code below. i want to stop the effect midway through the movie without stopping the movie. how do i use a stop command to do this?
init = function () {
width = 550;
// pixels
height = 400;
// pixels
max_snowsize = 15;
// pixels
snowflakes = 125;
// quantity
for (i=0; i<snowflakes; i++) {
t = attachMovie("snow", "snow"+i, i);
t._alpha = 20+Math.random()*60;
t._x = -(width/2)+Math.random()*(1.5*width);
t._y = -(height/2)+Math.random()*(1.5*height);
t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
t.k = 1+Math.random()*4;
t.wind = -1.5+Math.random()*(1*3);
t.onEnterFrame = mover;
}
};
mover = function() {
this._y += this.k;
this._x += this.wind;
if (this._y>height+10) {
this._y = -20;
}
if (this._x>width+20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
} else if (this._x<-20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
}
}
init();
Function Not Stopping At }?
I have the below functions, actually I have more but its just repetive.
When I click on any of my movieclips that are brickclick_, they run all functions starting from the bottom up?
So for an example using the code below: If I clicked on Brick 0, the functions would run for brickclick_1 then brickclick_0 and not just the one being clicked on.
And, the movieclip is just a movieclip created using createEmptyMovieClip.
Code:
_root.brickclick_0.onMouseUp = function()
{
trace("----------------");
trace(this);
LoadBrick(0);
}
_root.brickclick_0.onMouseMove = function(){
LoadToolTip(BrickArray[0][0]);
}
_root.brickclick_1.onMouseUp = function()
{
trace("----------------");
trace(1);
LoadBrick(1);
}
_root.brickclick_1.onMouseMove = function(){
LoadToolTip(BrickArray[1][0]);
}
Stopping A Function Mid Way
Hey everyone,
I currently have this function in my flash
function wait() {
gotoAndStop(19);
clearInterval(myTimer); .
}
myTimer = setInterval(wait, 6000);
however, sometimes I leave the page before it times out however it will continue to count down and change to that frame regardless of what im doing. Is there anyway to tell the function that if I leave the page its to stop working?
Natushi12
Stopping A Function
Seriously, and sadly, I've been trying to figure this out for over a month now. First of all, this is a flash 5 problem, if there are any more dinosaurs out there who haven't upgraded yet :( I have made a game that consists of two different planes flying across the screen. If there aren't enough of the planes, or if the plane passes a certain y position, the function is called again. If the planes hit the player's plane, the movie moves to frame four. Frame four doesn't have the enemy planes on it, but they still fly. I've tried:
function reset(stop)
after the "if" that contains the hittest for the two planes, but it simply stops the planes flying the after first time around. Below are the links to the page that conatins the game, as is, and also another link to the fla, you'll see that even after the player's plane is hit, the blue planes keep flying....if anyone has an answer, that would be great!!!
http://www.geocities.com/yellowraincoatman/MyShipArcade...
And the fla is at:
http://www.geocities.com/yellowraincoatman/MyShipArcade...
The blue and red plane are the ones in question, and they consist only in the second and third frame
Thanks,
Stopping A Function?
Hey everyone,
What I have is an mc with the following AS on it:
ActionScript Code:
on (release){
_root.mcHeader.gotoAndPlay(2);
}
What I am trying to do, is once this mc has been clicked, to shut the above function off. That way the user can't click again and run the mcHeader..
I would appreciate any input you guys have, as I am sorta thinking I might have to learn more abotu and create variables to control this?
thanks for your time!
Problem Stopping A Function
When the flash movie starts. a word will be printed with external jpg's. The letters of that word begin to animatie by the moveRandom function. When i klik on a movieclip the animation should stop but only for that movieclip. Can someone help me.
thx.
_tl = this;
_tl.woord = "carabas";
_tl.seconds = 2;
_tl.lengte = woord.length;
_tl.letters = woord.split("");
_tl.letter = letters.split(",");
char_arr = new Array();
for (j=0; j<lengte; j++) {
char_arr[j] = woord.slice(j, j+1);
}
for (i=0; i<lengte; i++) {
_tl.createEmptyMovieClip("letter"+i, i);
_tl["letter"+i]._x = 10+(50*(i));
_tl["letter"+i]._y = 350;
image = char_arr[i]+".jpg";
_tl["letter"+i].createEmptyMovieClip("loadClip_mc", 100+i);
_tl["letter"+i].loadClip_mc.loadMovie(image);
}
for (i=0; i<lengte; i++) {
_tl.createEmptyMovieClip("control"+i, i+100);
_tl["control"+i].iProp = i;
_tl["control"+i].onEnterFrame = function() {
_tl["letter"+this.iProp].iProp = this.iProp;
_tl["letter"+this.iProp].moveRandom(1, 1, 400, "bounce", 12);
};
}
//------> Here is the problem
//------> thought i should use delete onEnterFrame and clearInterval but that doesnt help neither.
for (i=0; i<lengte; i++) {
_tl["letter"+i].onPress = function() {
clearInterval(INTERVAL);
delete _tl["control"+this.iProp].onEnterFrame;
};
}
// max_dv -> maximum absolute velocity change
// maxV -> maximum absolute velocity
// freq -> frequency of velocity change
// behavior -> "bounce" or "mod"; action taken when instance hits boundaries; default action: bounce
// fps -> sets animation's FPS; generally set to movie's FPS, but can be overridden
MovieClip.prototype.moveRandom = function(max_dv, maxV, freq, behavior, fps) {
this.chgSpd = max_dv;
this.maxV = maxV;
this.freq = freq;
this.vx = this.chgSpd*(Math.random()*2-1);
this.vy = this.chgSpd*(Math.random()*2-1);
if (behavior == "bounce" || behavior != "mod") {
this.$mR = function() {
this._x += this.vx;
this._y += this.vy;
this.vx = (!(random(this.freq))) ? (this.vx+this.chgSpd*(Math.random()*2-1))%this.maxV : this.vx;
this.vy = (!(random(this.freq))) ? (this.vy+this.chgSpd*(Math.random()*2-1))%this.maxV : this.vy;
if (this._x>Stage.width || this._x<0) {
this.vx = -this.vx;
}
if (this._y>Stage.height || this._y<0) {
this.vy = -this.vy;
}
updateAfterEvent();
};
} else {
this.$mR = function() {
this._x += this.vx;
this._y += this.vy;
this.vx = (!(random(this.freq))) ? (this.vx+this.chgSpd*(Math.random()*2-1))%this.maxV : this.vx;
this.vy = (!(random(this.freq))) ? (this.vy+this.chgSpd*(Math.random()*2-1))%this.maxV : this.vy;
if (this._x>Stage.width) {
this._x %= Stage.width;
}
if (this._x<0) {
this._x = Stage.width-this._x;
}
if (this._y>Stage.height) {
this._y %= Stage.height;
}
if (this._y<0) {
this._y = Stage.height-this._y;
}
updateAfterEvent();
};
}
INTERVAL = setInterval(this, "$mR", 1000/fps);
};
Stopping A Function From Running
I have a function creating a new clip..
'function makeNewClip(){'
how do i stop the function from running?
//stop button
cow1stop_btn.onRelease=function(){
_root.makeNewClip()=false;
}
basically i want to set makenewclip=null?
Stopping A Function Firing
I’m using a setInterval function which fires only once to change a clips _x & _y locations & more importantly stop the function that is currently operating on the clip, basically stopping it’s rotation & sounds.
I have tried “delete” as in “delete functionName()” and also “delete functionName” as well as storing the function name in a variable & deleting that, but no joy.
Can anyone show me where I’m going wrong on this?
The function to stop (with setInterval in situ):
Code:
function spin() {
// The setIntverval function
function clear() {
thisOnename._x = 450;
thisOnename._y = 250;
delete _root.spin();
clearInterval(finish);
}
if (_root.cart == hit_txt) {
same = true;
}
if (track && same) {
_root.water_mc.play();
water_sound.start(0, 6);
_root.machine_txt.text = "";
thisOnename.swapDepths(_root.dum_mc);
_root.onEnterFrame = function() {
thisOnename._rotation += 10;
};
} else {
machine_txt.text = "Please try again!";
_root.stop_mc.gotoAndStop(2);
}
finish = setInterval(clear, 8000);
}
Function Stopping Mc Being Dragged
Firstly, I have 5 mc's which act as btns that can be dragged around the stage using swap depth. The problem is that when I add the code on to my frame, for example menu_5_mc. See below:
.onRelease = function(){
loadMovieNum("vrx.swf", 10)
}
The mc becomes inactive and is unable to be dragged and loses the ability to swap depth.
Secondly how can I create an overstate for the mc's/btn's when using a function?
cheers steph
Stopping A Function From Repeating...
Ok then, one more question...for the time being
I have an enemy spaceship/boss who fires lasers. The boss movie clip is physically on the stage.
I have made function enemylasers() on the main stage, and then call this from
the boss movie clip like so:
onClipEvent (load) {
shoot = setInterval(_root.enemylasers, 3000);
}
How can I stop the function? Ideally i want to use an on enter frame, if bossshields = 0 then kill function.
Any ideas? Im sure its just a simple command, but I cant seem to find it.
Thanks in advance
[F8] Stopping Drag Function
i need to stop a start/stop drag function.. inside another function.
i have a dragable box , when that hits a button it starts a function called add.
and in there i'd like to be able to stop the startDrag and stopDrag function.
help would be very nice.
thanks in advance
Stopping A Function (typewriter)
I have a function that writes a text to a textspace, with a typewriter effect.
This is the function:
Code:
function writeContent1() {
var str:String = "Lorem ipsum dolor sit amet, doming sequitur, claram futurum consectetuer seacula nam id aliquam molestie ipsum. Parum facer demonstraverunt non ii litterarum imperdiet nibh delenit. Duis consuetudium videntur eum liber processus ut typi laoreet. Decima facilisi nunc doming luptatum per autem formas, clari luptatum accumsan. In et vulputate qui minim, futurum nam lectores, usus nisl eorum. Consequat humanitatis praesent lobortis facer molestie eum aliquam consequat, at. Nostrud veniam vulputate mirum lorem, ad est feugiat eu, iusto nostrud. Suscipit facit per quarta decima tempor. Consectetuer seacula clari eua nobis sed volutpat te duis littera vel. Lectorum, saepius me tincidunt, anteposuerit cum erat imperdiet ex. Facit luptatum te eum notare decima futurum diam. Typi sed exerci me dignissim legentis. Est non at clari praesent, congue ad elit investigationes. Cum molestie fiant eua quod et eros eu id vel vulputate. Lobortis exerci, legunt ii in ex anteposuerit nobis, anteposuerit notare. Nibh usus sed nam, te legere videntur me. Est parum sit non at vero dolor quis per. Ad cum notare, investigationes eodem modo habent praesent. Nobis blandit eua et mutationem anteposuerit quarta eu claritas. Nulla nostrud seacula facilisi feugiat. Commodo erat sequitur liber possim. Fiant placerat id typi, ii per processus duis in mirum. Consequat mutationem demonstraverunt ex sit augue te mazim nunc.";
var sInt = setInterval(writeIt,1);
var count:Number = 0;
function writeIt() {
c1txt.text = str.substring(0,count);
count += 5;
if (count > str.length+5) {
clearInterval(sInt);
}
}
}
but when I try to re-execute the function or change the text directly (while the function is still continuing) it messesthings up. Nothing happens, or it really messes up.
What can I do to correct this problem ? I thought I have to stop the function first to write the other text.
Well, what I want to do is, to have a function like this
Code:
typewrite ("my text here");
And I want it to typewrite the text to c1txt.text
I hope I'm clear,
thank you.
Stopping A Function In Progress?
This function slides an image into place. But when another button using the same code is pressed (and the function is still working from the previous click), the last image does not reset to zero alpha.
Just trying to get it to show the image selected, but immediately stop and delete the onEnterFrame once another button is clicked? <learning>Would this be a good use of listeners? </learning>
Code:
function showMarquee(channel) {
//reset position back to starting point
channel._x = startingX;
_root.mrq_chan01._alpha = 0;
_root.mrq_chan02._alpha = 0;
_root.mrq_chan03._alpha = 0;
_root.mrq_chan04._alpha = 0;
_root.mrq_chan05._alpha = 0;
_root.mrq_chan06._alpha = 0;
// Assign action to perform on every frame of MovieClip
channel.onEnterFrame = function():Void {
// Fade up...
channel._alpha += 4;
// distance to target is the target's X minus the MovieClip's current X position
distanceX = targetX - channel._x;
movementX = distanceX / velocity;
channel._x += movementX;
// if mc has reached destination, remove action
if (Math.abs(channel._x - targetX) < 1) {
delete channel.onEnterFrame;
trace("deleted");
}
};
}
Stopping A Function OnMouseMove
hi all,
Im looking for a way to stop the silentMouse function from working once the mouse is moved again, I have added a comment to the end of the code to show where I would like to stop it from.
I dont know how to stop or clear the functions contained within silentMouse.
ActionScript Code:
var counter = 0;
setInterval( function(){ if(counter++ ==5){silentMouse()} }, 1000 );
function silentMouse(){
//trace("mouse hasn't moved for three seconds");
counter = 0;
delay = 2000; // 1second: 1000 ms
forwardInterval = setInterval(flip_mc, "flipForward", 3000);
flip_mc.onLastPage = function(){
clearInterval(forwardInterval);
lastPageInterval = setInterval(closeLastPage, delay);
};
function closeLastPage() {
flip_mc.flipGotoPage(0);
clearInterval(lastPageInterval);
forwardInterval = setInterval(flip_mc, "flipForward", 2000); };
}
onMouseMove = function(){
counter=0;
// I need silentMouse function to stop working from here
}
Any ideas appreciated.
Stopping A Function Call
Hi
I have this function
Code:
function playGlint1(e:TimerEvent):void {
var glintT1:Tween = new Tween (movies_mc.glint_mc, "x", Regular.easeInOut, -100, 100, 35, false);
glintT1.addEventListener(TweenEvent.MOTION_FINISH, playGlint2);
}
When I click one of the nav btns at 'just' the right moment (hence this does not occur every time) the 'playGlint2' function gets called from the listener then yeilds an error. I'm guessing coz the script has moved on, but the tween listener has called the function, so now I get an error - access of undefined property playGlint2().
I tried adding this to the btn action, but it gave me an error too. The path was wrong, so 'glintT1' could not be found.
Code:
homeButton.addEventListener(MouseEvent.MOUSE_DOWN, onHomeButton1);
function onHomeButton1(evt:MouseEvent):void {
glintT1.stop();
}
What is the correct syntax for stopping the function call or the tween?
Many thanks as always
mm66
[CS3, AS 2.0] Help Stopping A Looping Function
Hey all! I am a complete newbie when it comes to actionscripting. I followed a tutorial that creates falling snowflakes. The movie works fine by itself but my problem comes in when I copy the movie as a scene into another flash that has individual scenes as "commercials." When I run the movie, the snowflakes continue to fall throughout the other scenes. I know that I somehow have to stop the loop but I'm not sure how. I want it to just play for that scene (I have the background set to stop at 180 frames) I've tried looking at other posts and searching the internet and I think that I need to use clearInterval but I'm not sure where to put it or the exact syntax of how to write it. I understand what is written but not how to change it.
Any help is GREATLY appreciated!!! Thanks!!!
Here is my code:
this.createEmptyMovieClip("canvas_mc",10);
var i = 0;
myInterval = setInterval(addFlake,500);
function addFlake() {
if (i<20) {
var t:MovieClip = canvas_mc.attachMovie("snowflake","flake"+i,canvas _mc.getNextHighestDepth());
i++;
t._xscale = t._yscale = Math.random()*80+20;
t._x = Math.random()*Stage.width;
t._y = -50;
t._alpha = Math.random()*40+50;
}
}
Stopping A Function Loop
well its not really a loop in the strict programatic sense, but the effect is similar. I have a function attached to a button that uses the onEnterFrame event of an MC to start some action. When I rollout I want the action to stop, similar to using a clearInterval method.
I tried using the setInterval method to create the action but the values inside the interval function are only checked at the first call of the setInterval, not after each interval.
I'll admit I am far from a programer or any kind of expert in code, so my methodology may be completely whack. I am open to suggestions to better solutions...
FYI, here is the code I am using
scrollRight_btn.onRollOver = function(){
thumbScroll(+5);
}
scrollRight_btn.onRollOut = function(){
//need code here to end onEnterFrame cycle
}
// first attempt returned -5 continuously, instead of incrementing
scrollLeft_btn.onRollOver = function(){
scrollTime = setInterval(thumbScroll, 42, -5);
}
scrollLeft_btn.onRollOut = function(){
clearInterval(scrollTime);
}
thumbScroll = function(amt){
trace(thumbnailScroll_mc._x + amt);
thumbnailScroll_mc.onEnterFrame = function(){
if(thumbnailScroll_mc._x > 0){
thumbnailScroll_mc._x + amt;
}
}
}
Stopping A _root.onMouseDown = Function()
i have a:
Code:
_root.onMouseDown = function(){
someAction
}
and i want to stop this with a button. how can i do it?
i need something like this (i know its not how you do it, it just explains better...) :
Code:
on (press) {
stop the_root.onMouseDown = function()}
[CS3] Stopping The KeyPress Function From Repeating When Key Held Down
Hi,
It is important that I use the keyPress function for this to work rather than a listener.
When keyPress is used I want a score to be increased by 10 but that it wont keep increasing by 10 when held down. I want it to only increase by another 10 when the key has been released and then pressed again.
Can anyone help with this?
Stopping A Follow Mouse Function On Rollover Or Release
Hey Gang,
I'm trying to create a menu bar that follows your mouse vertically. I was following this tutorial:. http://webdesign.templatemonster.com...ouse.1244.html
but I can't seem to figure out how to stop the toolbar from following after rolling over or clicking on the movie clip. I also wanted to find out if I could adjust where the movie clip seats when it meets the mouse, as it seems to get stuck in a non-clickable area. Can anyone give me a bit of insight as to what I need to do to achieve this? Thanks in advance!
This is what the script looks like:.
Quote:
toolbar.onEnterFrame = function() {
var yMouse = _root._ymouse;
if(Math.abs(xMouse - this._x) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 6;
}
}
Jeff
PS: if this is in the wrong section, sorry in advance!
Stopping A Function And Return Back To Same Position - Help Needed
Any one pls help ,
Friends i have a function in that movieclips color will change according to time
what i need is if a specific action occurs say pressing a button (poweroff) or if the value of x==1; the function should be stopped where it is .....
if i press some other button say poweron the function should start again from the same place.....
Note: there is only one frame and stoping the movieclip like mc.stop(); not working in this case, return and killfunction completely get me out from the function.
function fadeArrayTrans(){
//trace("hai");
myCO = new Color(_root.lightsholder1.examplered1.SomeImageCli p);
myCO.fadeTransform(transArray[lastTransArray], 3750, fadeArrayTrans);
lastTransArray++;
//return;
lastTransArray%=transArray.length;
}
transArray = [];
transArray[0]={ra:100, rb:255, ga:100, gb:255, ba:100, bb:255, aa:100, ab:0};
transArray[1]={ra:100, rb:0, ga:100, gb:255, ba:100, bb:100, aa:100, ab:0};
transArray[2]={ra:100, rb:0, ga:100, gb:255, ba:100, bb:0, aa:100, ab:0};
transArray[3]={ra:100, rb:0, ga:100, gb:255, ba:100, bb:255, aa:100, ab:0};
transArray[4]={ra:100, rb:0, ga:100, gb:0, ba:100, bb:255, aa:100, ab:0};
transArray[5]={ra:100, rb:255, ga:100, gb:0, ba:100, bb:255, aa:100, ab:0};
transArray[6]={ra:100, rb:255, ga:100, gb:0, ba:100, bb:70, aa:100, ab:0};
transArray[7]={ra:100, rb:255, ga:100, gb:40, ba:100, bb:100, aa:100, ab:0};
lastTransArray = 0;
i have pasted small part of the code which may give idea about my problem. if you insist friends , i will post full script
Thanks in Advance
ENTER_FRAME Handler
i got a btn_mc on stage, 10 frames length, the width shape tweens from 1 -> 50
this is my actionscript :
ActionScript Code:
btn_mc.buttonMode = true;
btn_mc.addEventListener(MouseEvent.ROLL_OVER, btn_rollOver);
function btn_rollOver(event:MouseEvent):void
{
event.currentTarget.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
function btn_rollOut(event:MouseEvent):void
{
event.currentTarget.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
event.currentTarget.addEventListener(Event.ENTER_FRAME, exitFrameHandler);
}
function enterFrameHandler(event:Event):void
{
event.currentTarget.nextFrame();
event.currentTarget.addEventListener(MouseEvent.ROLL_OUT, btn_rollOut);
}
function exitFrameHandler(event:Event):void
{
btn_mc.prevFrame();
if (event.currentTarget.currentFrame == 1)
{
event.currentTarget.removeEventListener(Event.ENTER_FRAME, exitFrameHandler);
}
}
nextFrame() and prevFrame() seem to work allright, but you can manage to pause the prevFrame() function if you rollOver it again quickly.
so from what i can tell what is happening :
btn_mc gets a ROLL_OVER event, if ROLL_OVER event occurs, btn_mc enterFrameHandler starts running, and keeps playing nextFrame(). Also an ROLL_OUT event is added at this time. So when we ROLL_OUT, exitFrameHandler starts prevFrame() until the currentFrame of the btn_mc == 1, it then removes the exitFrameHandler.
what happens now is that when your ROLL_OVER, ROLL_OUT and immediatly ROLL_OVER again, the nextFrame() should be running again, but this doesnt happen, it seems enterFrameHandler is not being started, prevFrame() pauses on a certain frame, even though it is listening...
anyone care to see what the potential problem is ?
Kind regards,
Juan
Why Can't I Use ENTER_FRAME In A Timer?
Here's a piece my code:
ActionScript Code:
var imageTimer:Timer = new Timer(4000,1);
imageTimer.addEventListener(TimerEvent.TIMER, switchImage);
function switchImage(Event:TimerEvent):void
{
images[i].addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
basically, I have a bunch of MC's in an array, and when the timer goes off, it will start the animation to switch images using an EnterFrame event. Yet, when I test the movie, I get this error, pointing at the EventListener in my switchImage function....
1119: Access of possibly undefined property ENTER_FRAME through a reference with static type flash.events:TimerEvent.
What's wrong? Why can't I add an EnterFrame listener when a timer goes off??
Terminate ENTER_FRAME ?
Greetings,
I can't seem to get this to work:
stage.addEventListener(Event.ENTER_FRAME,startUp);
function startUp() {
rowsReq();
columnsReq();
matchDef();
_itemPosition();
if (stopEnterFunc == 1)
{
stage.removeEventListener(Event.ENTER_FRAME);
for (var i=1; i < 17; i++)
{
this['dry' + i]=this["_item" + i + "_drag"].y;
}
for (var j=1; j < 17; j++)
{
this['drx' + j]=this["_item" + j + "_drag"].x;
}
for (var k=1; k < 16; k++)
{
this['_item' + k + "_drag"]._txt.htmlText=dWords[k];
}
}
}
In AS2 this was easier, or so it seems. Just used:
delete this.onEnterFrame;
Any help will be greatly appreciated!
ENTER_FRAME Undefined?
This is the code of a little program I'm working on. It's pretty simple, but when I try to test it the following error occurs: "1119: Access of possibly undefined property ENTER_FRAME through a reference with static type flash.events:MouseEvent." Which is a little strange, considering that I have used almost the same syntax in some other cases and there wasn't any problem. Any help would be appreciated.
ActionScript Code:
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.events.Event;
var Vx:Number = 0;
var Vy:Number = 0;
var a:Number = 0.98;
var h:Number = 0;
var X:Number = 0;
var Y:Number = 0;
var ball:MovieClip = new MovieClip();
ball.x=ball.y=0;
this.addChild(ball);
var mc:MovieClip = new MovieClip();
mc.x=mc.y=0;
this.addChild(mc);
button_submit.addEventListener(MouseEvent.CLICK, EventReceiver);
function EventReceiver(Event:MouseEvent):void{
Vx = v_ns.value;
h = h_ns.value;
X = 0;
Y = 400 - h;
mc.graphics.clear();
mc.graphics.moveTo(0, 387-h);
mc.graphics.lineStyle(1, 0x000000);
mc.graphics.beginFill(0x000000);
mc.graphics.lineTo(40, 387-h);
mc.graphics.lineTo(40, 417-h);
mc.graphics.lineTo(0, 417-h);
mc.graphics.lineTo(0, 387-h);
mc.graphics.endFill();
addEventListener(Event.ENTER_FRAME, startAnimation);
}
function startAnimation(e:Event):void{
if(Y<400){
X += Vx;
Vy += a;
Y += Vy;
ball.graphics.clear();
ball.graphics.beginFill(0x000000);
ball.graphics.drawCircle(X,Y,13);
ball.graphics.endFill();
}
else {removeEventListener(Event.ENTER_FRAME, startAnimation);};
}
Problem With ENTER_FRAME Help Please
Just started migrating and am having problems with the enter frame event.Did a simple rotating star animation with the following code
import flash.events.*;
function rte(event:MouseEvent) {
function rotate(event:Event) {
m_mc.rotation+=40;
}
m_mc.addEventListener(Event.ENTER_FRAME,rotate);
}
b_mc.addEventListener(MouseEvent.CLICK,rte);
When I press the button (b_mc) more than once the star starts rotating faster every time.What is going on?Doesn't happen in AS 2.0
Event.ENTER_FRAME
Hi guys,
If I add an event listener for Event.ENTER_FRAME can it interupt my function ? This is what I mean:
public function myFunction() : void {
a=1;
b=2;
c=3;
// frame gets entered, will it jump to the listener function right here ?
d=4;
e=5;
f=6;
}
Thanks.
ENTER_FRAME Issue
Hi guys, I'm really quite new to actionscript let alone AS3, hopefully you can help me out with an issue I'm having.
I have a movieclip with instance name "Title" within my main timeline. I want to jump to a frame within "Title" labelled "Appear" whenever the playhead reaches a certain frame on the main timeline.
In AS2 I would have gone with onEnterFrame, but I'm not sure what to do with AS3. Here's what I've attempted, but it doesn't seem to work:
Code:
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
trace("MovieClip(root).Title.gotoAndPlay(Appear)");
}
removeEventListener(Event.ENTER_FRAME,myFunction);
Any help you could give would be great.
Thanks!
Better Than ENTER_FRAME For This Project?
I'm not a developer and over the course of the past year during which I've learned a lot of AS3, I have probably not come close to applying what would be considered "best practices." I have lots of code that could probably be dramatically changed to improve performance.
Here's a bit of my code that I'd like advice about. Is there a different technique I can use to do the following, that's more streamlined?
masterCounter is variable that's iterated every tenth of a second on the root timeline. The following code is in a movie clip that's been added to the stage:
PHP Code:
addEventListener(Event.ENTER_FRAME, s003Listener);function s003Listener(event:Event):void { if (!event.target.parent.masterIsPlaying) { pauseAudio(); } if (event.target.parent.masterIsPlaying) { resumeAudio(); } if (event.target.parent.masterCounter == 1) { startAudioBkgd(); } if (event.target.parent.masterCounter == 10) { startAudio01(); } if (event.target.parent.masterCounter == 50) { Tweener.addTween(s003Presented, {alpha:1, time:fade}); } if (event.target.parent.masterCounter == 62) { playWhoosh(); } if (event.target.parent.masterCounter == 65) { s003Presented.gotoAndPlay(2); } if (event.target.parent.masterCounter == 95) { Tweener.addTween(s003Presented, {alpha:0, time:fade}); Tweener.addTween(s003title, {alpha:0, time:fade}); }// ...etc. Imagine there are a hundred of these if statements...
Don't flame me for being a Flash Butcher!
Thanks for any help!
ENTER_FRAME Listeners..
so in an attempt to leave no stone unturned, I need to understand why things happen, when applying an ENTER_FRAME listener, does the code excecute as long as your on the frame, kinda like a loop but with no statement to stop it? for example I have the following code:
var contRotate:Number = 1;
stage.addEventListener(Event.ENTER_FRAME, spinWheel)
function spinWheel(e:Event) {
var bigWheelRotate:TequilaTween = new TequilaTween(bigWheel, {x:90});
bigWheelRotate.start();
bigWheel.x = contRotate + 1;
trace("wheel spinning");
}
the string"wheel spinning" keeps tracing, however,bigWheel doesnt rotate, so do ENTER_FRAMES excecute once, or as long as your on the frame?
Particals + ENTER_FRAME
Hi everyone.
I looked through the posts and don't think this has been covered yet.
I'm creating a smoke trail effect that moves from the left of the screen to the right using particles.
In order to know where to go, and to create a random effect each particle has its own ENTER_FRAME, and they are being created one-per-frame until they are removed at the other end. (this is all done in an external file).
By the time they begin being removed there are hundreds and the app slows down. My guess is that this is due to hundreds of ENTER_FRAMES running simultaneously.
I was wondering if there is any way to use a central ENTER_FRAME in the main file that simply 'fires' a function in all of the existing particles (to make them listen for a command rather than having separate ENTER_FRAME). This would reduce system load and keep individual movement.
Thanks in advance!
James
Conquering ENTER_FRAME :)
touching is a Boolean which is declared as false;
it becomes true in here:
PHP Code:
mc.addEventListener(MouseEvent.MOUSE_OVER, onRollOver); function onRollOver(e:MouseEvent):void { touching = true;}
and then false again in here:
PHP Code:
mc.addEventListener(MouseEvent.MOUSE_OUT, onRollOut); function onRollOut(e:MouseEvent):void { touching = false;}
first of all, i wanted to say it like this:
PHP Code:
if (touching == true) {addEventListener(Event.ENTER_FRAME, scrollMouse);function scrollMouse(e:Event):void { TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)}); }}if (touching == false) {removeEventListener(Event.ENTER_FRAME, scrollMouse);}
But it doesnt work, the listener is never added, dont understand why...
it WORKS like this:
PHP Code:
addEventListener(Event.ENTER_FRAME, scrollMouse);function scrollMouse(e:Event):void {if (touching == true) { TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)}); }}if (touching == false) {}
But it defeats a purpose of adding/removing event listener when not necessary, especially ENTER_FRAME.
how can i make this work so that i add that listener only when i want and remove it accordingly?
i dont want to have ENTER_FRAME on my neck all the time...
Slow Down ENTER_FRAME
I'm new to the whole Flash game, and I'm trying to slow down the ENTER_FRAME event... Now, I got it working but I was wondering if it's the best way?
Actionscript Code:
var scrollSpeed = 5;var scrollSpeedInc = 0;
myBtn.addEventListener(MouseEvent.ROLL_OVER, function(e:MouseEvent):void { myBtn.addEventListener(Event.ENTER_FRAME, startScroll);});myBtn.addEventListener(MouseEvent.ROLL_OUT, function(e:MouseEvent):void { myBtn.removeEventListener(Event.ENTER_FRAME, startScroll);}
function startScroll(e:Event):void { if (scrollSpeedInc < scrollSpeed) { scrollSpeedInc++; } else { // Scroll something. scrollSpeedInc = 0; }}
ENTER_FRAME Lags In CS4?
Hi all,
Apologies if this topic has already been posted but has anyone noticed a performance lag when using ENTER_FRAME in CS4? I had a very basic space invaders game created in Flash CS3 and it ran fine. When I took it into CS4 it was significantly slower. I stripped out everything but a few of the lines to change an Y property and it's still very slow, even with a frame rate of 60FPS. I've played around with the frame rate without success. Here's a snippet of the code...
stage.addEventListener(Event.ENTER_FRAME, loop);
function loop(myevent:Event) {
s1_mc.y+=2;
s2_mc.y+=2;
s3_mc.y+=2;
s4_mc.y+=2;
}
To me, these movie clips should move down the Stage quite fast at 60FPS but they actually drop quite slowly. It grinds even more when I throw in some hitTests. I don't have any other ENTER_FRAMEs going so I'm a little puzzled by this. I've also tested on Mac and PC with the same issue on both platforms.
Any feedback on this would be appreciated.
Gerald
GotoAndStop(); Not Running Along With ENTER_FRAME?
heya, theres probably a simple fix for this, but i dont get it.
the code is a mess and I guarantee some nooby items there, but it should all work, basically my button will do all its told in the function it runs, EXCEPT the jump to the next stage frame label? I think this is something to do with the enter_frame's i have going? any ideas?
Code:
select1.addEventListener(MouseEvent.CLICK , nStage2);
stage.addEventListener(Event.ENTER_FRAME , movement2);
stage.addEventListener(Event.ENTER_FRAME , movementb2);
function movementb2(event:Event):void
{
panpoint.distance = 115 - panpoint.mouseX
}
function movement2(event:Event):void
{
if (cityL1.x > 575) {
cityL1.x = 575;
} else if (cityL1.x <310) {
cityL1.x = 310;
}
if (cityL2.x > 575) {
cityL2.x = 575;
} else if (cityL2.x <310) {
cityL2.x = 310;
}
if (cityL3.x > 875) {
cityL3.x = 875;
} else if (cityL3.x <510) {
cityL3.x = 510;
}
var mod2a = cityL1.scaleX/105;
cityL1.x+=(panpoint.distance/10)*mod2a;
var mod2b = cityL2.scaleX/85;
cityL2.x+=(panpoint.distance/10)*mod2b;
var mod2c = cityL3.scaleX/65;
cityL3.x+=(panpoint.distance/5)*mod2c;
}
function nStage2(event:MouseEvent):void
{
stage.removeEventListener(Event.ENTER_FRAME , movement2);
stage.removeEventListener(Event.ENTER_FRAME , movementb2);
cityL1.mouseEnabled = false;
cityL2.mouseEnabled = false;
cityL3.mouseEnabled = false;
panpoint.mouseEnabled = false;
gotoAndStop("stage2");
trace ("clicked");
}
stop();
ENTER_FRAME Is Not On Line With Framerate?
i've got a problem, but dont know the cause.
i've got a class spaceship that has an object that handles his movement. this kinematic object updates the spaceShip's coordinates in a set interval.
then in the spaceship in an onEnterframe function everytime the spaceship exits the screen, it's coordinates are restored to the screen's boundaries. so that it does not exit.
but the problem is, that the space ship jumps in and out of the screen, because the kinematics object is taking care of its speed(pushing him out) and the spaceship object is trying to remain in the screen.
but i thought that the EnterFrame object is just before every frame update. so that would mean that everytime the screen is updated, the space ship is reset to the stage's boundaries, right?
this is the boundary checker:
PHP Code:
private function checkBoundaries():void { if (x > stage.width) { x = stage.width; } else if (x < 0) { x = 0; } if (y > stage.height) { y = stage.height; } else if (y < 0) { y = 0; } }
and:
PHP Code:
addEventListener(Event.ENTER_FRAME, checkBoundaries);
how come this doesn't work?
i can also just say:
PHP Code:
kine.myTimer.addEventListener(TimerEvent.TIMER, checkBoundaries);
but i just dont understand why this glitch is occurring
ENTER_FRAME:Event Issue
I have a video playing and when it completes (it's time property is greater than 3.3) buttons appear on the stage (AddChoiceGen2). When the user clicks one of the two buttons they are removed and the next video begins to play. This process is to continue numerous times.
The problem I'm having is that as soon as the buttons are removed from the stage the next set of buttons instantly appear (ignoring the videoStream.time). Is there a way to reset the .time before playing it again in the next video? Or do I need to reset something? Or do I need to do something different?
Any help is much appreciated. Thank you in advance.
PHP Code:
//monitor the video AddChoiceGen1
function checker1(ENTER_FRAME:Event):void{
if (videoStream.time >= 3.3) {
trace("VidGen1 is finished!");
AddChoiceGen2(null);
this.removeEventListener(Event.ENTER_FRAME, checker1);
}
}
//functions called by CLICK of buttons (Decision 1)
function vid1Play(CLICK:Event):void{
videoStream.play("vid1.flv");
//Monitor the video
this.addEventListener(Event.ENTER_FRAME, checker1);
}
Is Tweenlite Faster Than ENTER_FRAME ?
I am trying to make a simple accordeon menu, but when I fix one problem, I find another one. This time, it seems that the tweens ars quicker than my ENTER_FRAME....
here is the code of my Main class Document (Main.as):
Code:
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite {
private var _butArray:Array = new Array("but0", "but1", "but2");
private var _actualOverBut:Number;
public function Main()
{
for (var i:int = 0; i < _butArray.length; i++)
{
this[_butArray[i]].addEventListener(MouseEvent.ROLL_OVER, rollOver);
this[_butArray[i]].addEventListener(MouseEvent.ROLL_OUT, rollOut);
}
this.addEventListener(Event.ENTER_FRAME, replaceButtons);
}
private function rollOver(pEvt:MouseEvent):void
{
_actualOverBut = Number(pEvt.target.name.charAt(pEvt.target.name.length - 1));
pEvt.target.rollOverState(pEvt);
}
private function rollOut(pEvt:MouseEvent):void
{
pEvt.target.rollOutState(pEvt);
}
private function replaceButtons(pEvt:Event)
{
for (var i:int = 0; i < _butArray.length; i++)
{
if (_actualOverBut < i)
{
if (i != 0)
{
this[_butArray[i]].x = this[_butArray[i - 1]].x + this[_butArray[i - 1]].width + 1;
}
} else if (_actualOverBut > i)
{
if (i != _butArray.length - 1)
{
this[_butArray[i]].x = this[_butArray[i + 1]].x - this[_butArray[i]].width - 1;
}
}
}
}
}
}
and this is my Button class :
Code:
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import gs.TweenLite;
public class Button extends Sprite {
private var tDuration:Number;
private var originalX:Number;
private var originalY:Number;
private var targetX:Number;
private var targetY:Number;
private var originalWidth:Number;
private var originalHeight:Number;
private var targetWidth:Number;
private var targetHeight:Number;
public function Button()
{
originalWidth = this.width;
originalHeight = this.height;
targetWidth = originalWidth * 2;
targetHeight = originalHeight * 2;
originalX = this.x;
originalY = this.y;
targetX = originalX - ((targetWidth - originalWidth) / 2);
targetY = originalY;
tDuration = .3;
}
public function rollOverState(pEvt:MouseEvent):void
{
TweenLite.to(pEvt.target, tDuration, { x:targetX, y:targetY, width:targetWidth, height:targetHeight } );
}
public function rollOutState(pEvt:MouseEvent):void
{
TweenLite.to(pEvt.target, tDuration, { x:originalX, y:originalY, width:originalWidth, height:originalHeight } );
}
}
}
What I would to have as a result is the the buttons around the one that is rolled over keeps the 1 pixel bettwen each other....
Sorry, I can't upload my .FLA, but I can send by email if anyone interresting
Thank you
Problem With Reversing ENTER_FRAME
I'm posting my code:
Code:
iButton1.addEventListener(MouseEvent.ROLL_OVER, splitBox);
iButton1.addEventListener(MouseEvent.ROLL_OUT, closeBox);
function splitBox(evt:MouseEvent) {
iButton1.addEventListener(Event.ENTER_FRAME, slide);
}
function closeBox(evt:MouseEvent) {
iButton1.addEventListener(Event.ENTER_FRAME, back);
}
function slide(evt:Event):void {
Flap1_mc.rotation = -10;
Flap2_mc.rotation = 10;
Flap1_mc.x -= 5;
Flap2_mc.x += 5;
Flap1_mc.alpha = .7;
Flap2_mc.alpha = .7;
}
function back(evt:Event):void {
Flap1_mc.rotation = 0;
Flap2_mc.rotation = 0;
Flap1_mc.x = 265;
Flap2_mc.x = 281;
Flap1_mc.alpha = 1;
Flap2_mc.alpha = 1;
}
When I roll over my invisible button (iButton1), my movie clips Flap1_mc and Flap2_mc separate from each other side by side along the x-axis until I roll out.
My questions are:
1. How to reverse it. When I roll out, they go back to their original positions using enter frame so they don't just suddenly appear in their original position but move into original position along the x-axis. What am I missing?
2. I am unable to continue the function of splitting the movie clips when I roll out then roll over. When I roll over again, they don't continue splitting. Is my code in proper order?
Noob ENTER_FRAME Question
Hi, I've just started learning AS3 so I bought the book "Learning ActionScript 3.0". I copies one of the examples exactly as it was written in the book, yet I got the error: "1046: Type was not found or was not a compile-time constant: Event."
Here's the code (it tells me the error is on the line that says
"public function onLoop(evt:Event):void":
package
{
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Event;
public class Box extends MovieClip
{
public var color:uint = 0x000099;
public function Box()
{
//draw a shape at runtime
this.graphics.lineStyle(1, 0x000000);
this.graphics.beginFill(color);
this.graphics.drawRect(0, 0, 100, 100);
this.graphics.endFill();
this.addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
}
public function onLoop(evt:Event):void //Error line
{
this.x += 5;
}
}
}
Makes no sense to me why it refuses to work.
|