CallSub issues

Cableguy

Expert
Licensed User
Longtime User
It's me... again!!!

I have na Animation to do a simple fadein/fadeout with a smal twist...
The animation rest in a class module, so initialization is done in the main activity, then fadein animation is called... In the class I use only one animation object and a flag to perceive if the animationend event is triggered in a fadein or a fadeout in order to cal a particular sub in the Main activity...

so, I initialize the class, start the fadein, detect the end of the fadein and call the fadeout... all good ... except the callsub in the end of the fadeout is being trigered twice, and I can't figure out why!

B4X:
Sub FadeIn
   Fader.InitializeAlpha("Fader", 0, 1)
   Fader.Duration = 2000
   AnimFlag = 0
   Fader.Start(Pnl)
End Sub

Sub FadeOut
   Fader.InitializeAlpha("Fader", 1, 0)
   Fader.Duration = 1000
   AnimFlag = 1
   Fader.Start(Pnl)
End Sub

Private Sub Fader_AnimationEnd
   If AnimFlag = 0 Then CallSub(Main, "FadeIn_Ended")'"FadeIn_Ended" is a Sub in the Main Activity
   If AnimFlag = 1 Then
      Pnl.RemoveView
      CallSub(Main, "FadeOut_Ended")'"FadeOut_Ended" is a Sub in the Main Activity
   End If
End Sub

SOLUTION!

B4X:
Private Sub Fader_AnimationEnd
   If AnimFlag = 0 Then
        CallSub(Main, "FadeIn_Ended")'"FadeIn_Ended" is a Sub in the Main Activity
   Else If AnimFlag = 1 Then
      Pnl.RemoveView
      CallSub(Main, "FadeOut_Ended")'"FadeOut_Ended" is a Sub in the Main Activity
   End If
End Sub
 
Last edited:
Top