Function Help(){pt("SOS");} SetInterval(help,100);
Last edited by m3talsmith : 2002-11-22 at 17:04.
hehehe... Sorry about the title. Anyways here's the problem.
I'm making a preloader for xml without using frame loops; all actionscript. I've made it a prototype of xml with a built in timer, using intervals, to check the loading of the xml, and to keep the interval encapsulated(isn't this the purpose of OOP in the first place?).
Well the xml part goes fine but I don't see the timer triggering. Here's the code: Code: //#include "XML.prototype.preLoad.class"
XML.prototype.startTimer=function(rate){ this.rate=rate; if(this.rate==undefined){this.rate=100;} this.timerID=setInterval(this.checkLoaded, this.rate); trace("Timer started..."); } XML.prototype.stopTimer=function(){ clearInterval(this.timerID); trace("Timer stopped..."); }
XML.prototype.checkLoaded=function(){ if(this.tick){ this.tick++; trace(this.tick); if(this.loaded){ this.stopTimer(); trace("Loaded..."); } }else{this.tick=0;} }
XML.prototype.preLoad=function(XML){ trace("Loading..."); this.startTimer(100); this.load(XML); }
menu=new XML(); /*menu.onLoad=function(){ this.stopTimer(); trace("Loaded..."); //_root.stat="Loaded..."; }*/ //This was only there because my timer isn't triggering when xml is loaded :( //_root.stat="Loading..."; menu.preLoad("menu.xml"); Here's the xml: Code: <menu type="root" label="Menu(s)"> <menu type="folder" label="Rings" sitemap="true"> <menu type="item" label="Men's Bands" tooltip="View our Men's Bands" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=mensBands" /> <menu type="item" label="Eye Rings" tooltip="View our Eye Rings" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=er" /> <menu type="item" label="2-tone Bands" tooltip="View our 2-tone Bands" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=2t" /> <menu type="item" label="Armor Rings" tooltip="View our Armor Rings" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=armorRings" /> <menu type="item" label="Celtic Bands" tooltip="View our Celtic Bands" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=celticBands" /> <menu type="item" label="Toe Rings" tooltip="View our Toe Rings" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=T" /> </menu> <menu type="item" label="Pendants" tooltip="View our Pendants" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=CTGY&Store_Code=LWR&Category_Code=pend" /> <menu type="item" label="Entire Inventory" tooltip="View our entire inventory database. We like to call this our Showroom." href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=PLST&Store_Code=LWR" /> <menu type="item" label="Other Stuff" tooltip="View everything that we have planned to go into our database, but have just been to busy to get it there yet. You can make inqueries on any of these items for possible purchase and/or custom work. This is our jewelry showcase." href="file://localhost/Users/lem/Sites/lizardswizardsandringz/v3/showcase.htm" /> <menu type="folder" label="Shopping Cart" tooltip="Use your Shopping Cart"> <menu type="item" label="View Your Shopping Cart" tooltip="Use this to see if you have anything in your shopping cart or use shopping cart to add, remove, or just view the item(s) you may have" href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=BASK&Store_Code=LWR" /> <menu type="item" label="Check out at the Register" tooltip="Check Please! Use this to purchase all the items in your Shopping Cart." href="http://www.lizardswizardsandringz.com/Merchant2/merchant.mv?Screen=OINF&Store_Code=LWR" /> </menu> <menu type="folder" label="Site Navigation" tooltip="Navigate easily to the previous page, the home page, your favorites, etc..." sitemap="true"> <menu type="item" label="Return to the Home Page" tooltip="Go Home" href="home.htm" /> <menu type="item" label="Return to the previous page" tooltip="Go Back" href="javascript:history.back()" /> </menu> <menu type="folder" label="Site Information" tooltip="View contact information, request custom work, review information about the site, see current layaway and purchase policies" sitemap="true"> <menu type="item" label="Custom" tooltip="Request some custom work. We can do almost anything: the only real limitation is your imagination. Click here to email us your idea(s)!" href="mailto:info@lizardswizardsandrings.com" /> <menu type="item" label="Purchase and Layaway Policies" tooltip="See our site Policies" href="file://localhost/Users/lem/Sites/lizardswizardsandringz/v3/info.htm#layaway" /> <menu type="item" label="Contact Information" tooltip="Feel free to contact us" href="file://localhost/Users/lem/Sites/lizardswizardsandringz/v3/info.htm#contact" /> <menu type="item" label="Information about the site" tooltip="Site information such as words from our Leader and Head Jewelry, Angelo Roncari" href="file://localhost/Users/lem/Sites/lizardswizardsandringz/v3/info.htm" /> </menu> </menu> I can post the build an fla if needed.
Ultrashock Forums > Flash > ActionScript
Posted on: 2002-11-20
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
SetInterval Function Please Help
This function outputs 1 letter at a time. But continues run this same function over and over again. Anyone know how to stop this function after it finishes outputting the last character in the x value, and move onto the next frame.
y=0;
function printer()
{
x = "David";
output.text = x.charAt(y);
y++;
}
setInterval(printer, 1500);
Setinterval On Function
peepz,
i tried something with setInterval to disable a function for a few seconds, but is doesn't working:
Code:
onClipEvent(load){
//set some vars in the this.
this.speedY = 0;
this.speedX = 0;
this.damping = .7;
this.easing = .2;
this.homeX = this._x;
this.homeY = this._y;
//higher is more sticky
this.stickiness=4;
//bounce prototype
this.blaat = function(){
this.onEnterFrame = function(){
//if the mouse is not over the box
if (!this.hitTest(_root._xmouse, _root._ymouse) or this.pressed == true) {
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
} else {
//otherwise, drag me with some friction
difX = this._parent._xmouse-this.homeX;
difY = this._parent._ymouse-this.homeY;
this._x = this._parent._xmouse-(difX/this.stickiness);
this._y = this._parent._ymouse-(difY/this.stickiness);
}
}
}
this.blaat2 = function(){
this.onEnterFrame = function(){
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
}
}
}
on(rollOver){
this.blaat();
}
on(release){
setInterval(this.blaat(), 1000);
this.blaat2();
this.pressed = true;
}
its a sticky button and onrelease it has to bounce back!
maybe somebody can give me some advise?
thnx,
robert
SetInterval Function. . .
I need a little assistance in creating a setInterval function based on my xml file. If anyone could help, I would really appreciate it!
Here's a sample of xml file:
<count id="1">
<mediatype>1</mediatype>
<information>Introduction</information>
<endtime>12</endtime>
</count>
<count id="2">
<mediatype>2</mediatype>
<information>Clip 2</information>
<endtime>50</endtime>
</count>
<count id="3">
<mediatype>3</mediatype>
<information>Clip 3</information>
<endtime>150</endtime>
</count>
This is a sample of my actionscript:
Code:
myInterval = setInterval(beginFadeOut, time());
function beginFadeOut() {
clearInterval(myInterval);
mc.fadeIn(100, 7);
}
function time() {
sec = ((10/5)*1000);
trace("seconds called");
return sec;
}
eg.
sec = parent.childNodes[i].firstChild;
So, the value would be put in an array. I have tried several things, and have tried to ask the form, but no response.
If I need to post the .fla just let me know. Any assistance would be great!
Thanks,
cbs
Setinterval On Function
peepz,
i tried something with setInterval to disable a function for a few seconds, but is doesn't working:
ActionScript Code:
onClipEvent(load){
//set some vars in the this.
this.speedY = 0;
this.speedX = 0;
this.damping = .7;
this.easing = .2;
this.homeX = this._x;
this.homeY = this._y;
//higher is more sticky
this.stickiness=4;
//bounce prototype
this.blaat = function(){
this.onEnterFrame = function(){
//if the mouse is not over the box
if (!this.hitTest(_root._xmouse, _root._ymouse) or this.pressed == true) {
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
} else {
//otherwise, drag me with some friction
difX = this._parent._xmouse-this.homeX;
difY = this._parent._ymouse-this.homeY;
this._x = this._parent._xmouse-(difX/this.stickiness);
this._y = this._parent._ymouse-(difY/this.stickiness);
}
}
}
this.blaat2 = function(){
this.onEnterFrame = function(){
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
}
}
}
on(rollOver){
this.blaat();
}
on(release){
setInterval(this.blaat(), 1000);
this.blaat2();
this.pressed = true;
}
its a sticky button and onrelease it has to bounce back!
maybe somebody can give me some advise?
thnx,
robert
SetInterval Function
Hey guys,
I have a pretty simple question about the setInterval function (at least, I think it's simple). I am having a bit of a problem using it... I've never really used it before, and I'd much rather use it than do a frame count like I am usually doing.
Anyway, here's the code.
Code:
var ID:Number;
function tweenText() {
trace("pass");
var t1 = new Tween(this["cat"+i], "_alpha", Strong.easeOut, 0, 100, 50, false);
}
ID = setInterval(this, "tweenText", 2000);
basically, I want to run tweenText after 2000 milliseconds... Am I correc that this is what will happen? Am I using the correct structure?
-theonlycarmire
SetInterval Var And Function
obiously
function ["b" + var],
var ["b"+ ver] , and
setInterval(["b" + var],5) cannot work,
so is there any other way to use eval in functions , var and setInterval?
Trouble Using The SetInterval Function
I am trying to load in external swf files into a target movie clip randomly after a set period of time, but i am having trouble creating the code following the example from the sctionscript dictionary.
Can anyone help me??!!
I need the code to be in MX
HELP!
How Do I Make A Function? (for SetInterval)
hello people,
i have made a script wich i want to make in to "function" so that i kan use the setInterval. with the setInterval i want to update the script. but when i make this script a function it doesn't work.
the script works fine but it only works once and when you resize your browser it doesn't adjust to it (wich i want).
the code beneath must become a function, but how?? thanx
Code:
_root.createEmptyMovieClip("barTop", 2);
with (_root.barTop){
beginFill (0x666666, 100);
moveTo (0, 0);
lineTo (0, 0);
lineTo (0, 20);
lineTo (_root.stageMC._width, 20);
lineTo (_root.stageMC._width, 0);
endFill();
}
_root.createEmptyMovieClip("barTop2", 6);
with (_root.barTop2){
beginFill (0x333333, 100);
moveTo (0, 20);
lineTo (0, 20);
lineTo (0, 22);
lineTo (_root.stageMC._width, 22);
lineTo (_root.stageMC._width, 20);
endFill();
}
_root.createEmptyMovieClip("bg", 3);
with (_root.bg){
beginFill (0xCCCCCC, 100);
moveTo (0, 22);
lineTo (0, 22);
lineTo (0, _root.stageMC._height -20);
lineTo (_root.stageMC._width, _root.stageMC._height -20);
lineTo (_root.stageMC._width, 22);
endFill();
}
_root.createEmptyMovieClip("barBottom", 4);
with (_root.barBottom){
beginFill (0xFF6600, 100);
moveTo (0, _root.stageMC._height -20);
lineTo (0, _root.stageMC._height -20);
lineTo (0, Stage.height);
lineTo (_root.stageMC._width, _root.stageMC._height);
lineTo (_root.stageMC._width, _root.stageMC._height -20);
endFill();
}
_root.createEmptyMovieClip("welkomsbloktitle", 8);
with (_root.welkomsbloktitle){
beginFill (0x666666, 100);
moveTo (10, 32);
lineTo (10, 32);
lineTo (10, 52);
lineTo ((_root.stageMC._width/100)*32, 52);
lineTo ((_root.stageMC._width/100)*32, 32);
endFill();
}
_root.createEmptyMovieClip("welkomsblok", 7);
with (_root.welkomsblok){
beginFill (0xFFFFFF, 100);
moveTo (10, 52);
lineTo (10, 52);
lineTo (10, _root.stageMC._height -30);
lineTo ((_root.stageMC._width/100)*32, _root.stageMC._height -30);
lineTo ((_root.stageMC._width/100)*32, 52);
endFill();
}
//title
_root.createTextField("title", 5, 0, 0, 300, 20);
title.type = "dynamic";
title.html = false;
myTextFormat = new TextFormat();
myTextFormat.color = 0xFFFFFF;
myTextFormat.font = "Verdana";
myTextFormat.size = 10;
myTextFormat.bold = true;
myTextFormat.selectable = false;
title.text = ": Creating a interface from script : : :";
title.setTextFormat(myTextFormat);
_root.createTextField("welkomstitle", 9, 10, 33, 300, 20);
welkomstitle.type = "dynamic";
welkomstitle.html = false;
myTextFormat = new TextFormat();
myTextFormat.color = 0xFFFFFF;
myTextFormat.font = "Verdana";
myTextFormat.size = 10;
myTextFormat.bold = false;
myTextFormat.selectable = false;
welkomstitle.text = ": Welkoms tekst : : :";
welkomstitle.setTextFormat(myTextFormat);
to see it work check the *.fla
Local Function / SetInterval
Why are my local functions / setIntervals not working? I'm using this code, which should work fine.
code: pause = function () {
trace("wuddup");
thisClip.play();
thisClip.clearInterval(thisClip.stall);
}
thisClip.stall = setInterval(pause(), 3000);
I've attached the source below.... just open it and goto the "02-INTROS" folder. Choose the "01-introGettingStarted" MC.
Refreshing Function With SetInterval
Hi,
I´ve got problem when resetting function with setInterval. The set interval function adds 1 to variable which I would like to use in further scripting. But when I reset this function it does not reset that variable to start counting from 0. Can anybody look at that script and tell me what I had done wrong. It annoys me and I cannot get through this. I´ll be pleased for any suggestions.
Thanx, Meerah
Refreshing Function With SetInterval
Hi,
I´ve got problem when resetting function with setInterval. The set interval function adds 1 to variable which I would like to use in further scripting. But when I reset this function it does not reset that variable to start counting from 0. Can anybody look at that script and tell me what I had done wrong. It annoys me and I cannot get through this. I´ll be pleased for any suggestions.
Thanx, Meerah
Calling Function ONCE (w/ SetInterval)
Hi guys, I'm trying (with no success) to call a fucntion using setInterval only once, i want it to clearInterval Just after calling the function, but its just not working, can anyone help? the code to do that?
SetInterval Fired Up In A Function
I have written a class which I want to work with. It has a function which fires up an FS command which calls an external object. The FS call queries to see if a file exists. It waits for a returning boleean value to flag if the file exists, which does get returned.
Here is the problem:
Code:
this.loadFile = function(thisPath) {
var a = new Array();
thisVal = undefined;
thisVal = this.fileExists(thisPath);
coolio += "thats what I want";
};
....
this.fileExists = function(thisPath) {
returnVal = undefined;
aPath = thisPath;
// check to see if the file exists
fscomman("flashstudio.fileexists", "aPath,returnVal");
coolio = 0;
timerID = setInterval(checkReturn=function () {
if (returnVal == "true" || returnVal == "false") {
coolio += 1
clearInterval(timerID);
return (returnVal);
}}, 1000);
};
The issues is that the setInterval seems to get fored up in a seperate process. ie, the call from the loadFile function to the fileExists function should wait for its return value. This doesnt happen.....
I dont have this problem if I use setInterval outside of a class. As the logic flow is not dependant on it.
please please help...
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
SetInterval Inside Of A Function?
I can't seem to get the interval to call the function to play the next frame... Any help? thanks. I've tried to take out the single quotes.
code: function interval (btn, dir) {
function next () {
nextFrame ();
}
function back () {
prevFrame ();
}
btn.onEnterFrame = function () {
this.onRollOver = function () {
id = setInterval (dir, speed);
};
this.onRollOut = function () {
clearInterval (id);
};
};
}
interval (btn,'next')
interval (btn_back,'back')
Kill Function (setInterval)
peepz:
i have this to disable a function for a while but it isn't working:
Code:
on(rollOver){
this.blaat();
}
on(release){
setInterval(blaat, 10000000);
this.blaat2();
}
can someboydy help?
functions (they are for sticky buttons):
Code:
onClipEvent(load){
//set some vars in the this.
this.speedY = 0;
this.speedX = 0;
this.damping = .7;
this.easing = .2;
this.homeX = this._x;
this.homeY = this._y;
//higher is more sticky
this.stickiness=4;
//bounce prototype
this.blaat = function(){
this.onEnterFrame = function(){
//if the mouse is not over the box
if (!this.hitTest(_root._xmouse, _root._ymouse) or this.pressed == true) {
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
} else {
//otherwise, drag me with some friction
difX = this._parent._xmouse-this.homeX;
difY = this._parent._ymouse-this.homeY;
this._x = this._parent._xmouse-(difX/this.stickiness);
this._y = this._parent._ymouse-(difY/this.stickiness);
}
}
}
this.blaat2 = function(){
this.onEnterFrame = function(){
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
}
}
}
SetInterval W/ Anonymous Function
Ok, my actual code is much more complicated than this, but I've sheered it down as much as I can. Very little for you guys to look at.
Code:
createEmptyMovieClip("clip", 0);
clip.update = function() {
trace(this);
};
setInterval(clip.update, 500);
Very simply, the trace returns undefined every 500 ms. Calling clip.update() at any time normally and it works completely fine and returns clip. However, called from setInterval, it's giving undefined. You can trace clip.update from the function and that works fine also. So I'm not sure where it's losing the path. This is a rather curious problem... am I missing something obvious?
How To Use Setinterval With Function.apply()?
Hi there,
I am using the following code
Code:
motionMC.apply(text_mc,[100,1]);
function motionMC(endX,time) {
var mcTween:Tween = new Tween(this, "_x", Strong.easeOut, this._x, endX, time, true);
};
But I want to control the start time as well with setinterval
I tried
Code:
anime1 = setInterval(text_mc, "motionMC", 1000,[100, 1]);
SetInterval Inside A Function?
Hey guys, just ran into a bit of a snag ... trying to figure out why my code works outside of the main function, but not inside:
Code:
function thumbs():Void
{
var thumb:MovieClip;
thumbArray = new Array();
var duration:Number = 100;
var i:Number = 0;
//for (var i = 0; i < channelCount; i++)
//{
function runThumbs(){
var thumbData:Object = new Object;
deltaX = i - Math.floor(i / thumbsPerRow) * thumbsPerRow;
thumb = chan.attachMovie("c_thumb", "thumb" + i, zIndex++);
thumb._x = deltaX * (thumb._width + xSpacing) + thumbXBegin;
thumb._y = Math.floor(i / thumbsPerRow) * (thumb._height + ySpacing) + thumbYBegin;
thumbData.thumb = thumb;
thumbData.xPos = thumb._x;
thumbData.yPos = thumb._y;
thumbArray.push(thumbData);
thumb.setData(i, channels[i]);
img = "images/"+channels[i].cImg+".jpg";
image_mcl.addListener(imgListener);
image_mcl.loadClip(img, thumb.c_clip);
trace("executeCallback intervalId: " + intervalId + " count: " + i);
clearInterval(intervalId);
if(i < 10) {
i++;
intervalId = setInterval(this, "runThumbs", duration);
}
}
if(intervalId != null) {
clearInterval(intervalId);
}
intervalId = setInterval(this, "runThumbs", duration);
}
thumbs();
so if I take everything outside of the thumbs() function it works fine, but inside ... no go. I'm jsut learning about setinterval ...
oh ... and can someone please let me know what the "this" is inside the setInterval function. I know it's either function or object reference. But I'm still not clear on that part ...
Issue With SetInterval Function.
This is a simplified version of the actual project I'm working on, but it's basically set up the same way, I haven't been able to get much help from anyone on this yet, but maybe someone here will know how to deal with this
The main file contains a blank movie clip (loader_mc), it's set to load "mc_1.swf" by default. If one of the movie clips contained inside of mc_1.swf is clicked it changes the value of the _root variable stuff (_root.stuff) to 100. This is in turn supposed to then call the setInterval function callback0. I'm doing this because, in my more complex version, I need to have a delay to allow an animation to finish. The setInterval function callback0 is then supposed to load "mc_2.swf" into loader_mc. The problem is, for whatever reason, the damn thing gets caught in an endless loop that continually loads mc_2.swf.
Does anyone have a clue as to why it's doing this?
Here's the code, and I've also attached the entire project.
Code:
loadMovie("mc_1.swf","loader_mc");
_root.stuff = 0;
function callback0(){
clearInterval(intervalID);
loadMovie("mc_2.swf","loader_mc");
_root.stuff = 0;
}
function callback1(){
clearInterval(intervalID);
loadMovie("mc_1.swf","loader_mc");
_root.stuff = 0;
}
box.onEnterFrame = function(){
if(_root.stuff == 100){
intervalID = setInterval(callback0, 1000);
}
if(_root.stuff == 99){
intervalID = setInterval(callback1, 1000);
}
trace(stuff);
}
Refreshing Function With SetInterval
Hi,
I´ve got problem when resetting function with setInterval. The set interval function adds 1 to variable which I would like to use in further scripting. But when I reset this function it does not reset that variable to start counting from 0. Can anybody look at that script and tell me what I had done wrong. It annoys me and I cannot get through this. I´ll be pleased for any suggestions.
Thanx, Meerah
Return Function W/ SetInterval
I want to have a function that returns a value...this function will be called by setInterval.
The problem is...the function will return a value. I want to make sure that value goes to the proper variable. How can this be done?
Code:
EX:
function test(someInput){
return (someInput = 'dork');
}
interval_ID = setInterval(test, 10000, someInput);
// let's say i have a variable call "show"
// show should contain the return variable
Now, I tested out to see if I can pass a variable by address or reference to avoid 'return'...but it doesn't work. However, arrays can be used b/c it can be passed by referenced.
For example:
function test (theArray){
theArray[0]='dork';
}
var myArray = new Array();
myArray[0] = 'not a dork';
zeroArray(myArray);
trace (myArray[0]);
If you know how I can accomplish the same concept w/out using arrays, let me know.
thx in advance
Setinterval-function Functions Just Once
Hi!
I have a movieclip attached to a main movie.
ActionScript Code:
tritypes_btn.onPress=function() {
_root.attachMovie("tritypmove", "tritypmove_mc", 2)
_root.tritypmove_mc._x = 350;
_root.tritypmove_mc._y = 300;
}
The attached movieclip has four frames and the firs three frames have a setinterval-function.
ActionScript Code:
function wait3() {
_parent.gotoAndStop(4);
break;
}
timerHope3 = setInterval(wait3, 6000);
stop();
In the last frame of the movieclip the movieclip unloades with
ActionScript Code:
unloadMovie(tritypmove_mc);
Everything functions alright but when I press the buttone again which attach the movieclip the setintervals-functions on each movieclip does not function. Can someone explain this?
Kill Function (setInterval)
peepz:
i have this to disable a function for a while but it isn't working:
Code:
on(rollOver){
this.blaat();
}
on(release){
setInterval(blaat, 10000000);
this.blaat2();
}
can someboydy help?
functions (they are for sticky buttons):
Code:
onClipEvent(load){
//set some vars in the this.
this.speedY = 0;
this.speedX = 0;
this.damping = .7;
this.easing = .2;
this.homeX = this._x;
this.homeY = this._y;
//higher is more sticky
this.stickiness=4;
//bounce prototype
this.blaat = function(){
this.onEnterFrame = function(){
//if the mouse is not over the box
if (!this.hitTest(_root._xmouse, _root._ymouse) or this.pressed == true) {
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
} else {
//otherwise, drag me with some friction
difX = this._parent._xmouse-this.homeX;
difY = this._parent._ymouse-this.homeY;
this._x = this._parent._xmouse-(difX/this.stickiness);
this._y = this._parent._ymouse-(difY/this.stickiness);
}
}
}
this.blaat2 = function(){
this.onEnterFrame = function(){
//then bounce me home
this.bounceMe(this.homeX, this.homeY);
this.pressed = false;
}
}
}
Problem With SetInterval() Function
At the moment i am writing a small swf which uses the function setInterval().Here is the code
Quote:
function connect() {
for (i=0; i<100; i++) {
trace("Hello I am Interval()")
updateAfterEvent();
}
}
setInterval(connect(), 500);
In this code i want to output 100 messages "Hello I am Interval()" and this will loop every 500 (half of a second)... But it seems to be that the function connect() only loop for one time ,stop and do nothing.Did i do something wrong...Please correct me...
Adding SetInterval To A Function
Hi all,
I was just wondering if anyone could advise me on how to add an interval to this function
seven.onLoad = function(){
mx.transitions.TransitionManager.start(seven, {type:mx.transitions.Wipe, direction:0, duration:2.84, easing:mx.transitions.easing.Bounce.easeOut, startPoint:2, param2:empty});
};
I have tried to add a setInterval to this but it breaks the transition function.
All i want to do is to be able to make the above function wait for x amount of time before it is performed.
Thanks for any help anyone can offer
Jon saul
Cant Execute Function With SetInterval
ActionScript Code:
_root.logo._alpha = 0; //Sätt alpha på logon till 0_root.meny._alpha = 0; //Sätt alpha på menyn till 0var donealpha:Boolean = false; //skapa en Booleanvar doneshrink:Boolean = false; //skapa en Booleanvar donemove:Boolean = false; //skapa en Booleanvar doneenlarge:Boolean = false; //skapa en Booleanvar logorutashrink:Boolean = false; //skapa en Booleanvar menyalpha:Boolean = false; //skapa en Booleanvar logofadeID;var logoshrinkID;var menyalphaID;var doneenlargeID;var logorutashringID;var logomoveID;function logorutashrink(){ //Funktion för att förminska logorutanif(donealpha == true && doneshrink == true && donemove == true && doneenlarge == true){ //Om allt annat är klart if(_root.logoruta._yscale > 28){ //kolla så att logoruta är störra än 28 _root.logoruta._yscale -= 1; //minska med 1 }else{ //annars logorutashrink = true; //sätt logorutashrink till true clearInterval(logorutashringID); } }}function menyalpha(){ //Funktion för att fada fram menyn if(donealpha == true && doneshrink == true && donemove == true && doneenlarge == true && logorutashrink == true){ //om allt annat är klart if(_root.meny._alpha != 100){ //kolla så att alpha inte är 100 _root.meny._alpha += 1; //öka med 1 }else{ //annars menyalpha = true; //sätt menyalpha till true clearInterval(menyalphaID); } }}function logofade(){ //Funktion för att fada fram loggan if(_root.logo._alpha != 100){ //Kolla så att alpha in redan är 100 _root.logo._alpha += 1; //Om in så öka med 1 }else{ // om den är 100 donealpha = true; //Sätt donealpha booleanen till true clearInterval(logofadeID); }}function logoshrink(){ //Funktion för att minska loggan if(donealpha == true){ //Om logofade är klar så fortsätt if(_root.logo._xscale != 0 && doneshrink == false){ //kolla så att doneshrink är false och att xscale inte är 0 _root.logo._xscale -= 1; //Minska xscale med 1 _root.logo._yscale -= 1; //Minska yscale med 1 }else{ //om xscale är 0 eller doneshrink är true doneshrink = true; //sätt doneshrink till true clearInterval(logoshrinkID); } }}function logomove(){ //Funktion för att flytta loggan till vänstra hörnet if(donealpha == true && doneshrink == true){ //kolla så shrink och alpha på loggan är klara _root.logo._x = 30; //Flytta loggan till X 30 _root.logo._y = 30; //Flytta loggan till Y 30 donemove = true; //Sätt donemove till true clearInterval(logomoveID); }}function logoenlarge(){ //Funktion för att förstora loggan igen //trace(_root.logoruta._yscale); //trace("Alpha: " + donealpha + " Shrink: " + doneshrink + " Move: " + donemove + " Enlarge: " + doneenlarge + " Shrink: " + logorutashrink) if(donealpha == true && doneshrink == true && donemove == true){ //kolla så att dom 3 andra funktionerna är klara if(_root.logo._xscale == 40){ //kolla om xscale är 40 doneenlarge = true; //sätt doneenlarge till true clearInterval(doneenlargeID); }else{ //annars... _root.logo._xscale += 1; //öka xscale med 1 _root.logo._yscale += 1; //öka yscale med 1 } }}logofadeID = setInterval( logofade, 5); //kör logofade var 5:e mslogoshrinkID = setInterval( logoshrink, 8); //kör logoshrink var 8:e msmenyalphaID = setInterval( menyalpha, 5); //kör menyalpha var 5:e msdoneenlargeID = setInterval( logoenlarge, 8); //kör logoenlarge var 8:de mslogorutashringID = setInterval( logorutashrink, 5); //kör logorutashrink var 5:e mslogomoveID = setInterval( logomove, 1000); //kör logomove varje sekund
The first two functions wont get executed.. I have tried to put trace("test") strait under the function ...(){ but it wont execute it..
Any1 who can see the problem?
Best Regards
Latis
[FMX]setInterval MoveTo Function
I have four buttons on the stage which I want to move 20 pixels up (easing) and fade in from 0 to 100. But I want them to appear with a interval of 1 second. I came up with the following function:
Code:
function showClips(yPos, alpha, speed) {
var endY = yPos - this._y;
this._y += eindY /speed;
var endA = alpha - this._alpha;
this._alpha += endA / speed;
if (clips.length) {
clips[0]._visible = true;
clips.splice(0, 1);
} else {
clearInterval(id);
}
updateAfterEvent();
}
var clips = [];
var index = 0;
while (index++ < 4) {
var clip = eval("but_"+(index < 5 ? "0" : "")+index);
clip._visible = false;
clips.push(clip);
}
var id = setInterval(showClips, 1000, 304, 100, 3);
But it isn't working. The clips just appear on the stage without movement and fading. What is wrong with my function?
Setinterval For A Loop Function
Code:
_root.leftButton.onRelease = function() {
for(var i=0; i<6; i++){
animateThumbsToLeft(variable_1, variable2);
}
};
ok how and where do i put the setInterval script if i want to execute the "animateThumbsToLeft" function for 6 times and inbetween each time have a delay of say half a second...
i tried alot of ways and i still can't get it to work....
thanks
Clearing SetInterval From A Different Function
Could someone help me understand how to clear the interval in this code? I'd also like to know if there is a better way of firing makeStars() than using setInterval in a function - like I'm doing. I've looked at the Kirupa tutorial and I'm not seeing what should be done.
Basically, this attaches a number of stars within the Stage width and height properties. When the browser resizes I rewrite the stars to the screen with the new bounds. But I can't get the interval to stop, so the stars just keep getting replaced - disappearing and relocating abruptly.
It all works great outside of the resizeIt() function, but once inside she goes down hill from there. A couple of things I need cleared up (pun intended) are:
1. Am I creating a new interval each time resizeIt() is executed?
2.What is the scope of the interval(s), and does how you access them change depending on where you are in the code, or are they more global?
Thanks,
John
stop();
//number of stars to make
var numstars:Number = 100;
_root.attachMovie("background","bkgd",this.getNext HighestDepth());
var container = _root.createEmptyMovieClip("mycontainer",_root.get NextHighestDepth());
var w:Number = Stage.width;
var h:Number = Stage.height;
_root.mycontainer.lineStyle(1,0xFFFFFF,0);
_root.mycontainer.moveTo(0,0);
_root.mycontainer.lineTo(w,0);
_root.mycontainer.lineTo(w,h);
_root.mycontainer.lineTo(0,h);
_root.mycontainer.lineTo(0,0);
_root.mycontainer.endFill();
var n:Number = 0;
function makeStars():Void{
mycontainer.attachMovie("mcStar", "star"+n, n);
setProperty(mycontainer["star"+n], _y, Math.random() * Stage.height);
setProperty(mycontainer["star"+n], _x, Math.random() * Stage.width);
n++;
if(n == numstars){
//need interval cleared here to stop calling makeStars() from resizeIt() function.
clearInterval(intervalID);
n = 0;
}
}
Stage.align = "TL";
Stage.scaleMode = "noScale";
function resizeIt() {
_root.bkgd._width = Stage.width;
_root.bkgd._height = Stage.height;
_root.bkgd._x = _root.bkgd._width / 2;
_root.bkgd._y = _root.bkgd._height / 2;
bkgd.bwidth.text = Stage.width;
var intervalID:Number = setInterval(makeStars, 100);
}
var stageL:Object = new Object();
stageL.onResize = resizeIt;
Stage.addListener(stageL);
resizeIt();
onEnterFrame = function(){
//Moves stars off of mouse position and screen wraps.
for(var x:Number=0; x<numstars; x++){
setProperty(mycontainer["star"+x], _x, ((Stage.width/2 - _xmouse) * 0.03) + mycontainer["star"+x]._x);
setProperty(mycontainer["star"+x], _y, ((Stage.height/2 - _ymouse) * 0.03) + mycontainer["star"+x]._y);
if(mycontainer["star"+x]._x > Stage.width +25){
mycontainer["star"+x]._x -= Stage.width + 50;
}
else if(mycontainer["star"+x]._x < Stage.width - Stage.width -25){
mycontainer["star"+x]._x += Stage.width + 50;
}
if(mycontainer["star"+x]._y > Stage.height + 25){
mycontainer["star"+x]._y -= Stage.height + 50;
}
else if(mycontainer["star"+x]._y < Stage.height - Stage.height - 25){
mycontainer["star"+x]._y += Stage.height + 50;
}
}
}
[AS] SetInterval Corrupting Function?
Hi. I've made a function that hides a button, waits 5 seconds and turns it back on. When I run hideBtn(); for the three buttons only the first button works however the traces successfully output:
_level0.menuMC.homeBut
_level0.menuMC.aboutBut
_level0.menuMC.contBut
I'm thinking there is a problem with the setInterval. When I run the clearInterval the first time does it ruin it for the rest of the calls?
I'm sure there is a better way of doing it. Thanks for any help.
function hideBtn(cp) {
var currPath = cp;
currPath._visible = false;
wait = function() {
currPath._visible = true;
clearInterval(evoClr);
}
evoClr = setInterval(wait, 5000);
trace(currPath);
}
hideBtn(this._parent.homeBut);
hideBtn(this._parent.aboutBut);
hideBtn(this._parent.contBut);
How To Use Setinterval With Function.apply()?
Hi there,
I am using the following code
Code:
motionMC.apply(text_mc,[100,1]);
function motionMC(endX,time) {
var mcTween:Tween = new Tween(this, "_x", Strong.easeOut, this._x, endX, time, true);
};
But I want to control the start time as well with setinterval
I tried
Code:
anime1 = setInterval(text_mc, "motionMC", 1000,[100, 1]);
HELP With Wait Function SetInterval
FYI: I am really, really new to action script.
I have a movie clip symbol that is place on my main time line. I want the movie clip to display frames for (x) seconds then go to the next frame. I have a chunk of code that works by itself but when placed into my flash site it is causing some strange problems. Such as navigating to a label (page) prior to the movie clip that has the wait function code, freezes the flash. I am wondering if I need _root or a this in there somewhere.
The reason I want to do this is so I don't have to add a bunch of frames to get the pause time I need.
Is there a way to use the code below and not have it cause problems with the rest of my time line?
Here is the wait function code
stop();
i = 1;
function Wait() {
i++;
if (i == 7) {
gotoAndPlay(1);
} else {
nextFrame();
}
// or whatever script you would like...
// clearInterval(WaitInt); // to use the interval only once
}
WaitInt = setInterval(Wait, 5000);
// change to 5000 for 5 sec..
Here is a link where I downloaded the sample code
http://www.kirupa.com/forum/showthread.php?t=90221
Thanks for any help.
SetInterval On Attachmovie Function With X And Y Loc
HI. I'm new here. I have a function on my script that attaches a movieclip on a specific position and then it duplicates it several times. This movieclip has a code in order to move across the stage randomly. When I try to use SetInterval to repeat this function two weird things happen: the movieclips don't duplicate over that specific location (they appear on x=0,y=0) and if I set the location only one duplicates and the rest don't. My question is: what can I do to repeat the function every 2 seconds exactly as it is the first time it runs, without the objects not duplicating or moving from the original location?
Here's the code:
meteoros = function () {
this.attachMovie("asteroid","asteroid_mc",this.get NextHighestDepth());
asteroid_mc._x = 470;
asteroid_mc._y = 70;
//i++;
while (i<5) {
this.asteroid_mc.duplicateMovieClip("asteroid_mc"+ i,this.getNextHighestDepth());
i++;
}
};
setInterval(this,"meteoros",2000);
SetInterval Problem, Gives The Same Value Over And Over To Function
LATER EDIT: apparently, I managed to work around it. Anyway, the second setInterval was the one that did not work, and I put instead of:
setInterval(this, "setText", interval, setAcText());
this:
Code:
StratFlash = new setText(setAcText());
setText.prototype.updates = function() {
setText(setAcText())
// setText(setAcText());
};
setInterval(StratFlash, "updates", 4000);
to the second setInterval..
I have the following code that right now SHOULD do the following:
- show a different text every 2 seconds
Code:
// yay, starting..
/* the below setText creates the text to be shown in the flash and uses the parameter theText as the text */
function setText (theText:String):Void {
if(t != null) {t.removeTextField(); }
if(container != null) { container.removeMovieClip(); }
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
container.createTextField("t", this.getNextHighestDepth(), 30, 30, 150, 20);
var tf:TextField = container.t;
tf.text = theText;
}
/* here in function setAcText we declare the texts possible to be shown, and returning one */
var trr = null;
function setAcText():String {
num = Math.round(Math.random()*3);
switch (num) {
case 0:
trr = "New Worlds 0"; break ;
case 1:
trr = "New Worlds 1"; break ;
case 2:
trr = "New Worlds 2"; break ;
case 3:
trr = "New Worlds 3"; break ;
default:
trr = "New Worlds default";
}
return trr;
}
/* here we set an interval for the function to return a text, then an interval for the other function to construct a movieclip with a textfield to show that text */
var interval = 2000;
setInterval(this, "setAcText", interval)
setInterval(this, "setText", interval, setAcText());
stop();
The problem with it:
- the setAcText() returns a text, apparently setText grabs it but then it does this only once
- from my tests I seen that setText actually grabs another text returned from the setAcText, but heh, it still returns something
So, how can I actually make the setText do something, then do something else, then do something else, instead of actually doing the same thing over and over again?
Thank you!
Cant Execute Function With SetInterval
ActionScript Code:
_root.logo._alpha = 0; //Sätt alpha på logon till 0_root.meny._alpha = 0; //Sätt alpha på menyn till 0var donealpha:Boolean = false; //skapa en Booleanvar doneshrink:Boolean = false; //skapa en Booleanvar donemove:Boolean = false; //skapa en Booleanvar doneenlarge:Boolean = false; //skapa en Booleanvar logorutashrink:Boolean = false; //skapa en Booleanvar menyalpha:Boolean = false; //skapa en Booleanvar logofadeID;var logoshrinkID;var menyalphaID;var doneenlargeID;var logorutashringID;var logomoveID;function logorutashrink(){ //Funktion för att förminska logorutanif(donealpha == true && doneshrink == true && donemove == true && doneenlarge == true){ //Om allt annat är klart if(_root.logoruta._yscale > 28){ //kolla så att logoruta är störra än 28 _root.logoruta._yscale -= 1; //minska med 1 }else{ //annars logorutashrink = true; //sätt logorutashrink till true clearInterval(logorutashringID); } }}function menyalpha(){ //Funktion för att fada fram menyn if(donealpha == true && doneshrink == true && donemove == true && doneenlarge == true && logorutashrink == true){ //om allt annat är klart if(_root.meny._alpha != 100){ //kolla så att alpha inte är 100 _root.meny._alpha += 1; //öka med 1 }else{ //annars menyalpha = true; //sätt menyalpha till true clearInterval(menyalphaID); } }}function logofade(){ //Funktion för att fada fram loggan if(_root.logo._alpha != 100){ //Kolla så att alpha in redan är 100 _root.logo._alpha += 1; //Om in så öka med 1 }else{ // om den är 100 donealpha = true; //Sätt donealpha booleanen till true clearInterval(logofadeID); }}function logoshrink(){ //Funktion för att minska loggan if(donealpha == true){ //Om logofade är klar så fortsätt if(_root.logo._xscale != 0 && doneshrink == false){ //kolla så att doneshrink är false och att xscale inte är 0 _root.logo._xscale -= 1; //Minska xscale med 1 _root.logo._yscale -= 1; //Minska yscale med 1 }else{ //om xscale är 0 eller doneshrink är true doneshrink = true; //sätt doneshrink till true clearInterval(logoshrinkID); } }}function logomove(){ //Funktion för att flytta loggan till vänstra hörnet if(donealpha == true && doneshrink == true){ //kolla så shrink och alpha på loggan är klara _root.logo._x = 30; //Flytta loggan till X 30 _root.logo._y = 30; //Flytta loggan till Y 30 donemove = true; //Sätt donemove till true clearInterval(logomoveID); }}function logoenlarge(){ //Funktion för att förstora loggan igen //trace(_root.logoruta._yscale); //trace("Alpha: " + donealpha + " Shrink: " + doneshrink + " Move: " + donemove + " Enlarge: " + doneenlarge + " Shrink: " + logorutashrink) if(donealpha == true && doneshrink == true && donemove == true){ //kolla så att dom 3 andra funktionerna är klara if(_root.logo._xscale == 40){ //kolla om xscale är 40 doneenlarge = true; //sätt doneenlarge till true clearInterval(doneenlargeID); }else{ //annars... _root.logo._xscale += 1; //öka xscale med 1 _root.logo._yscale += 1; //öka yscale med 1 } }}logofadeID = setInterval( logofade, 5); //kör logofade var 5:e mslogoshrinkID = setInterval( logoshrink, 8); //kör logoshrink var 8:e msmenyalphaID = setInterval( menyalpha, 5); //kör menyalpha var 5:e msdoneenlargeID = setInterval( logoenlarge, 8); //kör logoenlarge var 8:de mslogorutashringID = setInterval( logorutashrink, 5); //kör logorutashrink var 5:e mslogomoveID = setInterval( logomove, 1000); //kör logomove varje sekund
The first two functions wont get executed.. I have tried to put trace("test") strait under the function ...(){ but it wont execute it..
Any1 who can see the problem?
Best Regards
Latis
[FMX]setInterval MoveTo Function
I have four buttons on the stage which I want to move 20 pixels up (easing) and fade in from 0 to 100. But I want them to appear with a interval of 1 second. I came up with the following function:
Code:
function showClips(yPos, alpha, speed) {
var endY = yPos - this._y;
this._y += eindY /speed;
var endA = alpha - this._alpha;
this._alpha += endA / speed;
if (clips.length) {
clips[0]._visible = true;
clips.splice(0, 1);
} else {
clearInterval(id);
}
updateAfterEvent();
}
var clips = [];
var index = 0;
while (index++ < 4) {
var clip = eval("but_"+(index < 5 ? "0" : "")+index);
clip._visible = false;
clips.push(clip);
}
var id = setInterval(showClips, 1000, 304, 100, 3);
But it isn't working. The clips just appear on the stage without movement and fading. What is wrong with my function?
SetInterval To Return A Value From A Function?
Got a little problem here guys... the story goes like this:
ActionScript Code:
function foo() {
function setValue() {
value = "ok";
}
return value
}
The problem here in my case is that the function setValue takes a couple of milliseconds to set the value variable. And when executing foo it returns undefined instead of "ok".
no problem, i'll just have foo return value with a setInterval:
ActionScript Code:
function foo() {
function setValue() {
value = "ok";
}
function checkIfSet() {
if (value) {
return value
}
}
setInterval(checkIfSet, 100);
}
...Ofcourse this doesnt work. Flash complains that there is no return value for the function foo.
What i'd need is fooScope.return value, if you catch my drift, but thats wishful coding
Can anyone help me out?
Thanks
Refreshing Function With SetInterval
Last edited by bambi : 2004-05-17 at 00:45.
Hi,
I´ve got problem when resetting function with setInterval. The set interval function adds 1 to variable which I would like to use in further scripting. But when I reset this function it does not reset that variable to start counting from 0. Can anybody look at that script and tell me what I had done wrong. It annoys me and I cannot get through this. I´ll be pleased for any suggestions.
Thanx, Meerah
Here is it:
ActionScript Code:
_global.alphafade = function() {
k = 0;
_global.fak = setInterval(function () {
if (k>13) {
clearInterval(fak);
k = 0;
trace("k="+k);
} else {
k=k+1
go();
trace("k="+k);
}
}, 500);
};
_global.go = function() {
kterej = _root["order"+k];
alphaFad(kterej);
};
_global.alphaFad = function(kterej) {
k = setInterval(initialize, 200, kterej);
};
_global.initialize = function(kterej) {
if (_root["alpha"+kterej]>90) {
clearInterval(k);
} else {
_root["alpha"+kterej] += 5;
}
};
on (release) {
for (j=0; j<15; j++) {
_root["alpha"+j] = 0;
}
_root.order1 = Number(1);
_root.order2 = Number(2);
_root.order3 = Number(3);
_root.order4 = Number(4);
_root.order5 = Number(5);
_root.order6 = Number(6);
clearInterval(fak);
alphafade();
}
SetInterval & Calling Function
Allright,
I call a function at each 10 milisecond using set interval. I have a problem calling function with set interval.
here is my code
xData="Yes";
xJack = setInterval( xJackDuff , 10, xData);
function xJackDuff(xData){
this["xS"+xData](); // Call the proper function.
// xSYes();
}
function xSYes(){
Trace("Now, i am calling the Yes function");
}
function xSNo(){
Trace("Now, i am calling the NO function");
}
My problem is the following piece of code:
this["xS"+xData]();
It works fine when i do not use setInterval, but when i do, it doesn't work.
Anyone have a clue why, is it because the setInterval is calling the function to fast, and it does'nt have time to render the code ?
Recursive Function With SetInterval
Last edited by cdMan : 2002-08-12 at 22:13.
why don't work??
Code:
fun = function () {
trace(getTimer()/1000);
setInterval(arguments.callee, 1000);
};
fun();
some idea?
SetInterval Will Not Initiate Function
I am trying to attach a movie to the stage and then animate it across stage.
but the interval is not calling the function every 2 seconds. I did a test and initiated the function with a button and everything works fine.
Code:
var speed:Number = 5;
var num:Number = 0;
var nInterval:Number = setInterval(loadSquare, 2000);
function loadSquare():Void {
trace("test");
var t:MovieClip = this.attachMovie("shape1", "shape"+num++, this.getNextHighestDepth());
t.gotoAndStop(Math.round(Math.random()*4));
t._x = Stage.width-50;
t._y = Math.random()*Stage.height+10;
t.onEnterFrame = mover;
}
function mover():Void {
this._x -= speed;
if (this._x<=0) {
this.removeMovieClip();
}
}
hope some one can help. Thank you all in advance.
Help W/ Escape From SetInterval Function...
title doesn't really explain it, i don't think, but...
oh, btw; hi, first post and all. i'm somewhat a beginner, so bear with me, pls.
i am using setInterval inside a function that calls an animation function, and calling the one with setInterval in it when an .mp3 loads - ie: plays. The effect is a db meter that bounces happily when i play the song.
my question is this: i want to stop the animation when the song stops. Currently i am calling a function with the stop button that feeds zeros to the animation, because i really don't know how to stop the original one - somehow missed that lesson . My problem is that it seems the two functions are fighting eachother. It works, but some of the control from the first function get through, so the db meter jumps occasionally. So (long post... sorry, i'm not good at explaining this stuff - i'll get better ) i want to stop the first animation function rather than start another one.
any suggestions?
PS: i really don't want to use frame actions for this. I know... call me stubborn.
thanx for any help you can give.
SetInterval Not Passing Paremeters To Function
I am having difficulties with passing parameters to a function when using setInterval. I've done it before but for some reason its not working in my current OOP set up.
the line i am using to create the interval is ::
this["this.fadeInterval" + this.myID] = setInterval(this.fadeAction, this.fadeRGBInterval, this.myID);
the interval name is being generated according to an ID number, "this.fadeAction" is the function and "this.fadeRGBInterval" is the interval. "this.myID" is the paremeter i wish to be passed.
i know that the interval is working cos the function "this.fadeAction" plays at the correct interval, but the paremeter is not being picked up.
why the problems? is it because i am generating the interval name on the fly?
any suggestions / tips much appreciated.
many thanks!
t
MX- Function Works OnMouseUp, Not With SetInterval
Hi,
seem to have something wrong with the following code.
a bug in my loop maybe
It draws curves between mc h12, using ctl mc as the control point to each of the mc's h0 to h9.
mc's are all dragable.
at the end I have two methods of calling the draw function. When testing I comment one or the other out. (only ever one active)
setInterval gives me a curve from h12 to 0,0
onMouseUp gives me all the curves to the h0 to 9 mc's
setInterval may be drawing 10 curves to 0,0, not sure.
code is in a mc on the root positioned at 0,0 that just contains the code
setInterval is the method I actually want to use
any idea whats going on
thanks mark
XStart = 100;
YStart = 0;
// attach the end point handles
for (i=0; i<10; i++) {
_root.attachMovie("squareHandle", "h" add i, i);
this["h" add i]._x = XStart;
this["h" add i]._y = YStart;
XStart = XStart - 10;
YStart = YStart + 10;
}
_root.attachMovie("squareHandle", "h12" , 12);
_root.attachMovie("roundHandle", "ctl", 11);
h12._x = 300;
h12._y = 100;
ctl._x = 188;
ctl._y = 225;
_root.createEmptyMovieClip("curve_mc", 13);
function draw() {
j = 0;
curve_mc.clear();
curve_mc.lineStyle(0, 0x000000);
for (j=0; j<10; j++) {
curve_mc.moveTo(h12._x, h12._y);
curve_mc.curveTo(ctl._x, ctl._y, this["h" add j]._x, this["h" add j]._y);
}
}
onMouseUp = draw;
//setInterval(draw, 25);
stop();
Return Value Of A Function Called By SetInterval
Just wondering how I can get the return value of a function called by setInterval.
for example
function hello() {
return "hello";
}
myinterval = setInterval(hello, 1000);
How do I get the return value "hello" from hello() function?
Clearing A SetInterval That Was Defined In A Function
Hi i hav edefined a setInterval call with a function ...however when i try clearing it as shown below it does NOT work!! does anyone know why this is..and how to clear the setInterval when it is defined within a function!! Thanks in advance!!
Code:
var changeInfo:Number;
_root.onEnterFrame=function(){
changeInfo = setInterval(greeting,1000);
}
function greeting(){
trace("hello");
}
my_btn.onRelease=function(){
delete _root.onEnterFrame;
clearInterval(changeInfo);
}
Button Will Not Call A SetInterval Function
hey guys...i;m not sure why this is not working. It's close. I spent some time learning the type effect with text. Great, got it. Now i would like to call new dynamic text when i click a button...and of course, this new text will be typed in the same effect. However, the function does not seem to want to be called, after the initinial load...any thoughts?
Code:
/////script to type
var g:Number = 0;
function typeIt(field, my_string) {
var frase:String = my_string;
field.text = "";
if (g<frase.length) {
field.text = frase.substring(0, g);
g++;
}
if (g>=frase.length) {
field.text = frase;
clearInterval(nTyper);
}
updateAfterEvent();
}
//////script for the text and text boxes
var rate = 20;
var nTyper:Number;
nTyper = setInterval(typeIt, rate, txBox, "this is my logo text");
nTyper = setInterval(typeIt, rate, button0.mc2.txBox, "Welcome");
nTyper = setInterval(typeIt, rate, button1.mc2.txBox, "category 1");
nTyper = setInterval(typeIt, rate, button2.mc2.txBox, "category 2");
nTyper = setInterval(typeIt, rate, button3.mc2.txBox, "Contact");
nTyper = setInterval(typeIt, rate, button4.mc2.txBox, "Recent");
var buttons:Array = [button0, button1, button2, button3, button4];
for (var i = 0; i<buttons.length; i++) {
buttons[i].onRollOver = function() {
this.gotoAndPlay(2);
};
buttons[i].onRollOut = function() {
this.onEnterFrame = function() {
if (this._currentframe>1) {
this.prevFrame();
}
if (this._currentframe<=1) {
delete this.onEnterFrame;
}
};
};
buttons[1].onRelease = function() {
nTyper = setInterval(typeIt, rate, txBox, "sub cat of category 1");
};//this is the part of the code that is not working
}
|