Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
use:
addChild(DisplayObject(c));
Copy link to clipboard
Copied
I have tried these with no success
#1
var c:MovieClip = MovieClip(RandomArray[0]);
addChild(DisplayObject(c));
#2
addChild(DisplayObject(RandomArray[0]));
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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()
////////////////////////////////////////////////////////////////////////
Copy link to clipboard
Copied
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);
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]);
Copy link to clipboard
Copied
problem solved! thanks anyway
Copy link to clipboard
Copied
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]);
Copy link to clipboard
Copied
I solved the problem..
Find more inspiration, events, and resources on the new Adobe Community
Explore Now