Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Press keyboard-key, then play randomly 1 of 7 videos

Community Beginner ,
Nov 30, 2017 Nov 30, 2017

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;

    }

}

TOPICS
ActionScript
196
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2017 Nov 30, 2017
LATEST

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:

KeyboardEvent Enter Key

You are creating functions inside other functions too, which makes it harder to understand.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines