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

Could someone help me out? ActionScript

New Here ,
Jul 29, 2014 Jul 29, 2014

import flash.display.MovieClip;

var clip:clip01 = new clip01;

var clip2:clip02 = new clip02;

var clip3:clip03 = new clip03;

var clip4:clip04 = new clip04;

var clip5:clip05 = new clip05;

var files:Array = [clip,clip2,clip3,clip4,clip5];

function randomizeArray(array:Array):Array

{

    var newArray:Array = new Array();

    while (array.length > 0)

newArray.push(array.splice(Math.floor(Math.random()*array.length), 1));

    return newArray;

}

var RandomArray:Array = randomizeArray(files);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

trace(RandomArray[0]);

trace(clip);

var c:MovieClip = MovieClip(RandomArray[0]);

addChild(clip); // it’s OK

addChild(c); // I get the error msg bellow:

Scene 1, Layer 'movies', Frame 1, Line 29              1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.

Could someone help me out?

I cannot add MovieClip on the stage from the array.

TOPICS
ActionScript
245
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
Community Expert ,
Jul 29, 2014 Jul 29, 2014

use:

addChild(DisplayObject(c));

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
New Here ,
Jul 29, 2014 Jul 29, 2014

I have tried these with no success

#1

var c:MovieClip = MovieClip(RandomArray[0]);

addChild(DisplayObject(c));

#2

addChild(DisplayObject(RandomArray[0]));

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
Community Expert ,
Jul 29, 2014 Jul 29, 2014

attach a screenshot of the error message, and your code so we can see the code line numbers, and the timeline so we can see that there is code in only 1 layer of frame 1.

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
New Here ,
Jul 29, 2014 Jul 29, 2014

import flash.display.MovieClip;

var clip1:clip01 = new clip01;

var clip2:clip02 = new clip02;

var clip3:clip03 = new clip03;

var clip4:clip04 = new clip04;

var clip5:clip05 = new clip05;

var files:Array = ;

function randomizeArray(array:Array):Array

{

var newArray:Array = new Array();

while (array.length > 0)

newArray.push(array.splice(Math.floor

(Math.random()*array.length), 1));

return newArray;

}

var RandomArray:Array = randomizeArray(files);

trace(RandomArray[0]);

trace(clip1);

var c:MovieClip = MovieClip(RandomArray[0]); //I think the problem starts

here

addChild(DisplayObject(c));

////////////////////////////////////////////////////////////////////////

TypeError: Error #1034: Type Coercion failed: cannot convert []@3ff5aee1 to

flash.display.MovieClip.

at RandomVideo_fla::MainTimeline/frame1()

////////////////////////////////////////////////////////////////////////

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
New Here ,
Jul 29, 2014 Jul 29, 2014

I need some more technical help on something in AS. I would like different movie clips to be playing on the stage in a random order and repeat forever. I need to add to the code an EventListener which sees the movie clip end and starting to play the next movie clip. I already have used timer, but it’s not good, because I want to watch the whole movie clip so ignore the timer in the code. Could you show me a solution?

import flash.display.MovieClip;

var clip1:clip01 = new clip01  ;

var clip2:clip02 = new clip02  ;

var clip3:clip03 = new clip03  ;

var clip4:clip04 = new clip04  ;

var clip5:clip05 = new clip05  ;

var files:Array = new Array();

pushArray(clip1,clip2,clip3,clip4,clip5);

function pushArray(c1,c2,c3,c4,c5:MovieClip){

                files.push(c1);

                files.push(c2);

                files.push(c3);

                files.push(c4);

                files.push(c5);

                }

function randomizeArray(array:Array):Array

{

                var newArray:Array = new Array();

                while (array.length > 0)

                {

                                newArray.push(array.splice(Math.floor

                                (Math.random()*array.length), 1)[0]);

                }

                return newArray;

}

var RandomArray:Array = randomizeArray(files);

var testTimer:Timer = new Timer(1000);

  1. testTimer.addEventListener(TimerEvent.TIMER,updateFile);
  2. testTimer.start();

function updateFile(event:TimerEvent):void

{

                if (RandomArray.length == 0)

                {

pushArray(clip1,clip2,clip3,clip4,clip5);

                                RandomArray = randomizeArray(files);

                }

                trace('play file',RandomArray[0]);

                RandomArray.shift();

               

}

//addChild(RandomArray[0]);

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
New Here ,
Jul 29, 2014 Jul 29, 2014

problem solved! thanks anyway

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
New Here ,
Jul 29, 2014 Jul 29, 2014

I have done till this the following code bellow. I’d like movie clip on the

stage to be playing one after another in a randomized order in a loop. I

used a timer, but this solution is not good, because the movies are not

playing till the end. I need an EventListener to listen the end of the clip.

How this code could be modified to work well, could you give me a solution

to this problem?

import flash.display.MovieClip;

var clip1:clip01 = new clip01 ;

var clip2:clip02 = new clip02 ;

var clip3:clip03 = new clip03 ;

var clip4:clip04 = new clip04 ;

var clip5:clip05 = new clip05 ;

var files:Array = new Array();

pushArray(clip1,clip2,clip3,clip4,clip5);

function pushArray(c1,c2,c3,c4,c5:MovieClip){

files.push(c1);

files.push(c2);

files.push(c3);

files.push(c4);

files.push(c5);

}

function randomizeArray(array:Array):Array

{

var newArray:Array = new Array();

while (array.length > 0)

{

newArray.push(array.splice(Math.floor

(Math.random()*array.length), 1)[0]);

}

return newArray;

}

var RandomArray:Array = randomizeArray(files);

var testTimer:Timer = new Timer(1000);

testTimer.addEventListener(TimerEvent.TIMER,updateFile);

testTimer.start();

function updateFile(event:TimerEvent):void

{

if (RandomArray.length == 0)

{

pushArray(clip1,clip2,clip3,clip4,clip5);

RandomArray = randomizeArray(files);

}

trace('play file',RandomArray[0]);

RandomArray.shift();

}

//RandomArray[0].addEventListener(Event.ENTER_FRAME, VideoFinished);

function VideoFinished(e:Event):void {

if (RandomArray[0].currentFrame==RandomArray[0].totalFrames) {

trace("finished");

}

}

//addChild(RandomArray[0]);

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
New Here ,
Jul 30, 2014 Jul 30, 2014
LATEST

I solved the problem..

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