PDA

View Full Version : How to make AMS 'listen' while looping?


longedge
08-28-2004, 05:19 PM
We went for a hot air balloon ride yesterday :D :yes - as soon as we got home I started to put a slideshow together and I thought I'd fade the pics in and out using Image.SetOpacity.

I created two functions in global functions fadein() and fadeout() using a while loop to set the opacity. It worked exactly as I expected until I tried to exit and there is no way I can get out of my application. I have to 'end' with ctrl-alt-del.

Is there a "correct" way of doing this? i.e. making AMS responsive to an Exit Button or right click "Exit" or "alt/F4" or "Window Close Button" while it's looping.

TJ_Tigger
08-28-2004, 08:34 PM
We went for a hot air balloon ride yesterday :D :yes - as soon as we got home I started to put a slideshow together and I thought I'd fade the pics in and out using Image.SetOpacity.

I created two functions in global functions fadein() and fadeout() using a while loop to set the opacity. It worked exactly as I expected until I tried to exit and there is no way I can get out of my application. I have to 'end' with ctrl-alt-del.

Is there a "correct" way of doing this? i.e. making AMS responsive to an Exit Button or right click "Exit" or "alt/F4" or "Window Close Button" while it's looping.

I would suggest trying to use the timer to work the fadein() and fadeout() functions. Set the timer to about 50 milliseconds and then set a variable to either fadein or fadeout so the right function is called. Hope this helps.

longedge
08-29-2004, 07:31 AM
Thanks for the suggestion Tigg except for the timing I think that's pretty much what I've done. My structure is very straightforward as set out below, but the runtime just won't close unless I use either Windows Task Manager or right click it on the Task Bar and end it. It works perfectly except for closing :lol

Global Functions -
function fadein()
while (opac<100) do
opac=opac+5
Image.SetOpacity("Image1", opac);
end
end

function fadeout()
while (opac>0) do
opac=opac-5
Image.SetOpacity("Image1", opac);
end
end

------------------------------------------
On preload -
Page.StartTimer(10500);
--Set variables.
n=1
opac=100
nbasetime=0
ntime=0

------------------------------------------
On Timer -
--Fade out the existing picture.
fadeout()

--Create the name of the next picture.
-- 54 pictures in this set.
n=n+1
if (n>54) then n=1 end
img="AutoPlay\\Images\\"..n..".jpg"

--Load the picture and fade it in.
Image.Load("Image1", img);
fadein()

--Worms timer for 6 seconds.
ntime = 0
nbasetime=String.ToNumber(DLL.CallFunction(_System Folder .. "\\winmm.dll", "timeGetTime"))

while (ntime < 6000) do
ntime=String.ToNumber(DLL.CallFunction(_SystemFold er .. "\\winmm.dll", "timeGetTime", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)) - nbasetime
end

------------------------------------------

On Show - it doesn't seem to make
any difference whether the Page.StartTimer is here
or On Preload. So this is blank.

TJ_Tigger
08-29-2004, 08:08 AM
I will see if I can throw something together. The while loop will prevent you from interacting with your project while the while loop is occuring. Try to do the same thing in the function without a while loop and with a timer. I don't have time right now, but I will see if i can have something by tomorrow.

Tigg

longedge
08-29-2004, 08:28 AM
I will see if I can throw something together. The while loop will prevent you from interacting with your project while the while loop is occuring. Try to do the same thing in the function without a while loop and with a timer. I don't have time right now, but I will see if i can have something by tomorrow.

Tigg

That's very good of you Tigg - it's a conceptual leap into the dark for me trying to achieve what I was after without the loops that are causing the problem. I had it working fine just using a next and previous button. It's a bit like going back to the times before multi-tasking.

Don't waste any valuable time on it - although I'll be very grateful if you do 'show me the way'.

Worm
08-30-2004, 01:33 PM
here's a sample app of something similar. I was going to write a function for doing cross-fades on images back when I was writing the Page Transition Plug-Ins. I never took it much farther than this, but it does read in a folder of images, and then performs a slide show, cross-fading the images.

longedge
08-30-2004, 03:04 PM
Worm - many thanks. I've had a quick look and can see it'll take me a while to pick through your example and understand where I've been going wrong (apart from trying to do too much in one go rather than breaking things down into smaller chunks) :yes .

ps - In fact I can see straight away the answer to one of the things that I was puzzling over i.e. How to set the page timer for 50ms and still have the pictures showing for x seconds handled by the timer event (I wish I was a programmer :lol )

Worm
08-30-2004, 03:18 PM
I know it's a bit scrambled, but it was merely a test app for me a while back. I tried to comment it as best I could. My intentions were to get the image objects to resize proprtionaly to the images and center within a given area, but as you can see, I never made it that far.

Too much fun to be had, and too little time.

As for the timer using 50 ms intervals; there are more ways to do it rather than use the winmm.dll. You coulde use a counter variable that is incremented on each cycle, once it has cycled 20 times, a second has past. So you could test to see when the counter was 120 (6 * 20) process the swap.

Intrigued
08-30-2004, 03:47 PM
I know it's a bit scrambled, but it was merely a test app for me a while back. I tried to comment it as best I could. My intentions were to get the image objects to resize proprtionaly to the images and center within a given area, but as you can see, I never made it that far.

Too much fun to be had, and too little time.

As for the timer using 50 ms intervals; there are more ways to do it rather than use the winmm.dll. You coulde use a counter variable that is incremented on each cycle, once it has cycled 20 times, a second has past. So you could test to see when the counter was 120 (6 * 20) process the swap.
I also have used an invisible System.GetTime action where I only choose the seconds portion (it's an option) and then use that as a seperate counter (if you do not have say a clock display in place already in your application).

Then when the counter hits from 0 to 59 seconds I can have other actions fire off. And then you can also then add in the counter variable if that is needed, to keep track of the 'revolutions' (times that 0 thru 59 seconds has competed).

Sincerely,

longedge
08-30-2004, 03:58 PM
I know it's a bit scrambled

Not at all - it's perfectly formed in my eyes and something that I can only aspire to :lol - actually I was commenting on my ability to understand, you know the old use both brain cells at once syndrome. It's very tiring - have to have a little snooze every couple of hours when the cranium gets overheated...

Re the timer - what I mean is that although it fires every 50ms the processes taking place within the timer event are taking several seconds. I couldn't get my head round firing it multiple times before it's finished what it's doing, if you see what I mean.

Just to go back to my original question - the answer seems to be that AMS cannot respond to input whilst it's looping, you just have keep letting it 'come up for air'.

TJ_Tigger
08-30-2004, 07:09 PM
thanks Worm. Nice test app. I am finding that I am running out of hours in the day.

Tigg