Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top