Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 9:39 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Pro to Flex Conversion-scripting "wait"
PostPosted: April 2nd, 2010, 12:10 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi,

I'm trying to covert a regular Pro v7 pub into a Flex v7 version and am not sure how to replace the Flex-unsupported "wait" feature in the script.

Is there another way to create a delay (3 waits in the script: wait (60), and 2 that are based on a calculation-a variable's value * .05: wait (bar2*.05)?
Here's one of the scripts (original script with a lot of help from Mack):

Code:
function minuteTimer()
{
breakLoop = false
stopLoop = false
//fork (calcBreathing)

for (var i=0;i<time1;i++)
   {
      //wait(60)
   breakLoop = true
   Submit.Show()
   Text122.Show()
   Text12.Show()
   TextInput22.Show()
   TextInput2.Show()
   Submit2.Hide()
   TextInput2.SetTransparency(0,false)
   TextInput22.SetTransparency(0,false)
   Text12.SetTransparency(0,false)
   Text122.SetTransparency(0,false)
   Text5.SetTransparency(0,false)
   Frame12.SetTransparency(0,false)
   Submit.SetTransparency(0,false)
   TextInput2.Enable(true)
   TextInput22.Enable(true)

   Debug.trace("\n minutes elapsed "+(i+1)+"\n")
    }
   
stopLoop = true   
}


and here's the second, again the original script with a lot of help from Mack (note: since "fork" is also Flex-unsupported, I took it out of the script and substituted a standard "simultaneous" action in a start button):

Code:
function calcBreathing()
{

   
   var bar2 = 60/bar1

   for (loop = 0;loop<bar1;loop++)
      {
      mySound.Play(1,volume)
      Vector8.Scale(.5,.5, bar2*.3)
      mySound.Stop()
      //wait (bar2*.05)
      mySound2.Play(1,volume)
      Vector8.Scale(-.5,-.5,bar2*.6)
      mySound2.Stop()
      //wait (bar2*.05)
      if (breakLoop) break
      }
   
   
   breakLoop = false
   if (bar1 > 6) bar1--
   if (!stopLoop) calcBreathing()
}


Unfortunately, these "wait" scripts are critical to the entire script working correctly, so I need to figure out a substitute/work-a-round.

In searching this forum, I found an interesting idea but, since the sample file is not posted, cannot figure out how to implement it:
http://www.digitalgrapevine.info/viewtopic.php?f=4&t=3848&hilit=wait+flex.

Any suggestions appreciated.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
 Post subject: Re: Pro to Flex Conversion-scripting "wait"
PostPosted: April 2nd, 2010, 6:04 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Hi Stephen,

Here's one 'ticker example'. You might find others in a Search.
viewtopic.php?f=13&t=3549&hilit=ticker+example

Is this post about the 'breathing' -- am I going crazy, or did you edit the earlier post?

If the ticker doesn't work out, you could create a bounce effect and combine that with collision detection to change a variable or set-off another action. Either a bounce animation or a move along a circular path will give you a 'loop' for timing. You'll have to test it for accuracy and repeatability. Opus information on Flex says that 'functions return immediately'. Still, I think you can initiate an animation and it will run for whatever time specified.

I had played with something like that before and it worked pretty well. Of course in scripts you can vary the time durations much more easily using variables. Also, IsIntersecting() command can build the 'collision' trigger.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Pro to Flex Conversion-scripting "wait"
PostPosted: April 2nd, 2010, 7:07 pm 
Offline
User avatar

Joined: October 25th, 2004, 10:33 am
Posts: 257
Location: UK
Opus: Pro 8
OS: Windows 7 Professional x64
System: Dell XPS15 i7x4 2.1Ghz 6GB 128GB SSD
We went to a lot of effort to connect up the wait function, because we knew it would make it about a thousand times easier to do exactly the sorts of things you're doing here.

Unfortunately, Macromedia didn't. :wink: In Flash, each script runs in it's entirety before the screen is updated, which means your loop will run round 60 times and nothing will be visible. What you need is a function that is called for every frame (which you can do with a ticker trigger) which updates the current state of the objects.

So instead of:

Code:
function DoScale()
{
var scale = 1.0;
for(scale = 1.0 ; scale < 10; scale++)
{
   myObject.SetScale(scale, scale);
   wait(0.1)
}


Code:
var currentScale = 1.0;

function UpdateScale()                 // call from ticker trigger set to 0.1
{
  myObject.SetScale(currentScale, currentScale);

  if(currentScale >= 10.0)
  {
      return true;     // return true to say it's finished
    }
   currentScale++;
   return false;      // return false to say it's still running
}



To do multiple things like your example, you need to implement what old computer scientists would call a state machine:

Code:
var currentStep = 0;

function Update()
{
   switch(currentStep)
   {
      case 0:     // do animation
         // state 0 means doing scale
         if(UpdateScale())
         {
            // finished, set state to 1 so that on the next call it'll go onto the next step
            currentStep = 1;
         
         }
         break;
         
      case 1:      // play sound
         PlaySound();      // starts sound playing
         currentStep = 2;   // will go to state 2 next time
         break;
         
      case 2:      // wait for sound
         if(SoundFinished())
         {
            currentStep = 3;   // go onto next step
         }
         break;
         
      case 3:   // finished
         return true;   // return true to say finished
      
    }

   return false;   // still doing stuff

}



I hope that's not too terrifying, but it's the best way. The other thing of course is that you could probably do what you want with actions. Opus is doing something not unlike the above when you use actions.


Top
 Profile Visit website  
 
 Post subject: Re: Pro to Flex Conversion-scripting "wait"
PostPosted: April 2nd, 2010, 7:54 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Dave,

Thanks for that detailed reply and suggestions.

Whew! It does look challenging. :? But, I can try to figure it out and implement it in my project. I started to check if Flash AS has any wait/delay language. There is a setInterval, but I'm not sure (1) it can be used in an Opus Flex script and (2) if it would substitute for wait/delay.

I'll keep at it. If I can get the Pro pub converted into Flex, then it will allow use by a non-Windows audience as well.

BTW, Larry: yes, it's the same breath pacing tool from earlier posts. Works great, with much help from my forum colleagues, in a Pro version. Wanted to make it available to non-Windows users through Flex/Flash.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 57 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group