View Full Version : [FMX] loop question
wetodit
September 12th, 2003, 09:39 AM
I am trying to fade in a dynamic image, but when I try this bit of code, it seems to go into an infinite loop.
I'm confused, because it makes sence to me :/
It seems to always crash when I do the WHILE part (i've tried different while loops)
do {
fadein()
}
while (this._alpha < 100)
fadein = function() {
if(this._alpha < 100){
this._alpha += 5;
}
}
Any suggestions?
Thank you!
TOOL
September 12th, 2003, 10:33 AM
I don't know much about actionscript but I have been programming this year. Shouldn't it be something like this?
while (this._alpha < 100)
do
{
fadein()
}
fadein = function()
{
if (this._alpha < 100
{
this._alpha += 5;
}
}
So the loop condition is before you call do? I'm probably wrong but that could help?
Johnny64
September 12th, 2003, 10:51 AM
put the function before the while like this
fadein = function() {
if(this._alpha < 100){
this._alpha += 5;
}
}
do {
fadein()
} while (this._alpha < 100)
flash reads form top to botton
;)
TOOL
September 12th, 2003, 10:53 AM
Ahh well I was close enough. :)
wetodit
September 12th, 2003, 11:41 AM
Alright, that stops the infinite loop! Thank you!
HOWEVER, it still does not "fade" the picture! What gives?
Is there a better way of fading in a picture?
Thanks yet again!
wetodit
Johnny64
September 12th, 2003, 03:46 PM
Well thats because the loops for,for_in,do_while,while. loops as fast as your computer can, so it loops in a split sec.
To make it fade you should use an interval or use the frame rate of your movie
//interval
fadein = function () {
if (this._alpha<100) {
this._alpha += 5;
} else {
clearInterval(intervalID);
}
};
intervalID = setInterval(fadein, 100);
//or frame rater
this.onEnterFrame = function() {
if (this._alpha<100) {
this._alpha += 5;
} else {
delete this.onEnterFrame;
}
};
;)
wetodit
September 12th, 2003, 08:53 PM
Master64,
I'm not really sure if I messed this up, but the bit you provided did not function. I pasted the code near the top of my actionscript, and it seems to only add 5 to the alpha. I'm not really sure there's a loop, is there?
Thanks for your advice as I try to learn this thing!
wetodit
Johnny64
September 13th, 2003, 01:07 PM
Well first there are two scripts there so you should not use both.
They both loop but in the interval one here should have no this. <--my mistake ;)
here is a example.
to find what onEnterFrame and Interval does look it up in the
flash help ;) here is a interval tut http://www.umbc.edu/interactive/fla...p?p=setInterval
;)
Johnny64
September 13th, 2003, 01:08 PM
oops here
wetodit
September 14th, 2003, 01:50 PM
Thanks M64...I'm still trying to figure this out ;)
wetodit
September 15th, 2003, 06:24 PM
It's me again... ;)
I got the fade effect to work, but now I have run into another problem. Can you tell me why this is happening?
No matter how you click (top button first, then 2nd; or 2nd then the top).
I think everything would be fine if I knew how to make the "holder" forget all the previous settings. I've attempted
onClipEvent (enterFrame) {
this.clear;
}
but that didn't work. ;)
Here is a link to my example:
http://www.stjosephmessenger.com/gb/pct.htm
I'd really appreciated your help once again.
Thanks,
wetodit
Johnny64
September 16th, 2003, 02:18 AM
Well you only changed 1 sitting, so you could just
this._alpha = 0
there reseted
;)
if you post the fla i might beable to do more...
wetodit
September 17th, 2003, 02:54 PM
Master64,
I will post the FLA later tonight, but what I trying to do is just to add a "reset" action to the button
on (release) {
...
}
event.
Thanks,
wetodit
wetodit
September 18th, 2003, 05:43 PM
M64, I got it!
Now, it's nothing spectacular that I did, and I thought I read somewhere that it didn't work, but I tried it anyhow.
Instead of:
if (this._width>640 || this._height>480) {
this._xscale = this._yscale=Math.min(100*640/this._width, 100*480/this._height);
}
I did this:
if (this._width>640 || this._height>480) {
this._width=640;
this._height=480;
}
Weird, huh?
Oh, and on the fade in function you provided, how can I get it to apply to every image, not just the first one?
Thanks,
wetodit
http://www.stjosephmessenger.com/gb/pct.htm
Scootman
September 18th, 2003, 06:35 PM
do {
fadein()
}
while (this._alpha < 100)
umm that is the original...
i believe on do while loops, after the while statement you need a semicolon... maybe that would've solved it?
while (this._alpha < 100);
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.