Copy link to clipboard
Copied
I want a simply function where I press the Enter-Key and then randomly 1 out of 7 imported videos starts playing.
Every video should be invisible first and should go invisible again after playing.
I tried to create it based on information I found, but I have the feeling it is very wrong and there are even simpler ways to create it
What is the best and simpliest Actionscript code to get this effect?
The name of the videos are video1, video2, video3, video4, video5, video6, video7.
Here is just for reference my code (but I guess there is not that much to take out of it):
video1.visible = false;
video2.visible = false;
video3.visible = false;
video4.visible = false;
var SelectMC:Number = 0;
addEventListener(KeyboardEvent.ENTER);
function fl_ClickToHide(event:KeyboardEvent):void
{
function getMC() :void
{
var SelRam:Number = Math.random ();
SelectMC = Math.round (SelRam*4+1);
trace(SelectMC);
}
getMC();
}
stage.addEventListener (Event.ENTER_FRAME,EntFrame);
function EntFrame(e:Event):void
{
}
if (SelectMC == 1)
{
video2.visible = false;
video3.visible = false;
video4.visible = false;
video1.visible = true;
}
if (SelectMC == 2)
{
video1.visible = false;
video3.visible = false;
video4.visible = false;
video2.visible = true;
}
if (SelectMC == 3)
{
video1.visible = false;
video2.visible = false;
video4.visible = false;
video3.visible = true;
}
if (SelectMC == 4)
{
video1.visible = false;
video2.visible = false;
video3.visible = false;
video4.visible = true;
}
}
Copy link to clipboard
Copied
This line has a problem:
addEventListener(KeyboardEvent.ENTER);
I think you want it to be:
addEventListener(KeyboardEvent.ENTER,fl_ClickToHide);
The KeyboardEvent.ENTER seems like a good idea, but I think it doesn't exist. See this topic about how to know when the Enter key is pressed:
You are creating functions inside other functions too, which makes it harder to understand.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now