Hi, I'm just tring to get to grips with label animation and have the following problem. Using the first code, the three labels fade in one after the other as expected when the animation is initiated by the Button Click event. However, in the 2nd code, I've called a sub which initiates the animation but what happens is the 3 labels fade together then the 2nd disappears and fades in, then the 3rd disappears and fades in. What is the difference in the two codes? Is it something to do with the LabelsSt array? Really need an answer for this because I know I will want to initiate animation depending on a variable in the future and not initiated from a Button Clic event. Thanks in advance>
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lblst0,lblst1,lblst2 As Label
Dim LabelsSt() As Label
Dim a1,a2, a3 As Animation
Dim btn1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Main")
a1.InitializeAlpha("Animation",0,1)
'lblSt.Initialize("")
'a2.InitializeTranslate("Animation",100dip,100dip,200dip,200dip)
a2.InitializeAlpha("Animation",0,1)
a3.InitializeAlpha("Animation",0,1)
lblst0.Tag=a1
lblst1.Tag=a2
lblst2.Tag=a3
lblst0.Text="Animation Test"
lblst1.Text="Animation Test 2"
lblst2.text="Animation Test 3"
LabelsSt=Array As Label(lblst0,lblst1,lblst2)
Dim animations() As Animation
animations=Array As Animation(a1,a2,a3)
For i=0 To animations.Length-1
animations(i).Duration=5000
animations(i).RepeatCount=0
Next
lblst0.Visible=False
lblst1.Visible=False
lblst2.Visible=False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btn1_Click
Dim a As Animation
lblst0.Visible=True
a=lblst0.Tag
a.Start(lblst0)
End Sub
Sub Animation_AnimationEnd
If Sender = a1 Then
lblst1.Visible=True
a2.Start(lblst1)
Else If Sender=a2 Then
lblst2.visible=True
a3.start(lblst2)
End If
End Sub
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lblst0,lblst1,lblst2 As Label
Dim LabelsSt() As Label
Dim a1,a2, a3 As Animation
Dim btn1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("Main")
a1.InitializeAlpha("Animation",0,1)
'lblSt.Initialize("")
'a2.InitializeTranslate("Animation",100dip,100dip,200dip,200dip)
a2.InitializeAlpha("Animation",0,1)
a3.InitializeAlpha("Animation",0,1)
lblst0.Tag=a1
lblst1.Tag=a2
lblst2.Tag=a3
lblst0.Text="Animation Test"
lblst1.Text="Animation Test 2"
lblst2.text="Animation Test 3"
LabelsSt=Array As Label(lblst0,lblst1,lblst2)
Dim animations() As Animation
animations=Array As Animation(a1,a2,a3)
For i=0 To animations.Length-1
animations(i).Duration=5000
animations(i).RepeatCount=0
Next
lblst0.Visible=False
lblst1.Visible=False
lblst2.Visible=False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btn1_Click
animate_Labels
End Sub
Sub animate_Labels
For i=0 To 2
Dim a As Animation
LabelsSt(i).Visible=True
a=LabelsSt(i).Tag
a.Start(LabelsSt(i))
Next
End Sub
Sub Animation_AnimationEnd
If Sender = a1 Then
lblst1.Visible=True
a2.Start(lblst1)
Else If Sender=a2 Then
lblst2.visible=True
a3.start(lblst2)
End If
End Sub