0

I want to create a video player from another stack and set autoplay.

I have created the object "player" in stack 1. To create a player in stack 2, I click on a button.

This is the code in the button:

set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"

This code is working. But the player doesn't autoplay.

Mark
  • 2,380
  • 11
  • 29
  • 49
KemChat
  • 151
  • 3
  • 11

1 Answers1

0

You just need to start the player after copying it.

set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
start player myNumberOfPlayers of card "object" of stack "stack2"

Sometimes it may be a good idea to send the play command after finishing the handler:

set the filename of player "Player" of card "object" to "myurl"
copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
send "startPlayer myNumberOfPlayer" to me in 0 millisecs

on startPlayer thePlayerNumber
   start player thePlayerNumber of cd "object" of stack "stack2"
end startPlayer

It might also be a good idea to set the filename after copying it:

copy player "Player" of card "object" to stack "stack2"
put the number of players of card "object" of stack "stack2" into myNumberOfPlayers
set the filename of player myNumberOfPlayer of card "object" of stack "stack2" to "myurl"
send "startPlayer myNumberOfPlayer" to me in 0 millisecs

on startPlayer thePlayerNumber
   start player thePlayerNumber of card "object" of stack "stack2"
end startPlayer

If you want to start playing the player control automatically when the card opens, just put the start player command into an openCard handler in the card script of card "object" of stack "stack2":

on openCard
  put the number of players into myNumberOfPlayers
  if myNumberOfPlayers > 0 then
    start player myNumberOfPlayers
  end if
end openCard
Mark
  • 2,380
  • 11
  • 29
  • 49
  • Thank you so much!.Your code is working.But when I close the card of new stack and open it again.The player is not autoplay.Have anyway for fix problem ? – KemChat May 06 '14 at 03:23
  • You didn't ask this in your original question. I have edited my answer to show how to do this. If this helps, please click on the checkmark next to my answer to "accept" the answer. You may also want to click on the upper triangle to vote for it. – Mark May 06 '14 at 07:40