Copy link to clipboard
Copied
Sorry in advance: I'm a beginner.
I created 10 movie clips, set up the linkage so each exports to ActionScript, created an array of all 10, typed up the addChild row so it loads my movie clips on the stage, and now have to display each one then fade it out (one by one). I've tried two for loops listed in my Classroom In A Book textbook, but my .swf only shows whatever image is on top with no change or has them all fade together into a mess of drawings. My two attempted codes follow. Can someone tell me what I'm missing to get them to go oneself at a time?
Attempt 1:
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Create an array of the 10 movie clips.
var clipArray:Array = new Array (One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten);
//Create an array of the movie clips on the stage.
var clipsOnstage:Array = new Array();
//Add the clips to the stage at a random order, one by one, until all 10 (and only 10) are on the stage
for (var i:int = 0; i < 10; i++) {
var pickClip = clipArray[int(Math.random() * clipArray.length)];
var clip:MovieClip = new pickClip();
addChild(clip);
clip.x = 158;
clip.y = 158;
}
//Add a function to the stage that steps through the clips, one by one.
stage.addEventListener(Event.ENTER_FRAME, showClip);
//Detail what I want that function to do.
function showClip(e:Event):void {
for (var i:int = clipsOnstage.length-1; i > -1; i--) {
//For the current movie clip displayed, fade it out, but don't display the next one until the first one is faded out.
var currentClip:MovieClip = clipsOnstage;
var tweenFadeOut:Tween = new Tween(currentClip, "alpha", None.easeOut, 1, 0, 3, true);
}
}
Attempt 2:
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Create an array of the 10 movie clips.
var clipArray:Array = new Array (One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten);
//Create an array of the movie clips on the stage.
var clipsOnstage:Array = new Array();
//Add the clips to the stage at a random order, one by one, until all 10 (and only 10) are on the stage.
for (var i:int = 0; i < 10; i++) {
var pickClip = clipArray[int(Math.random() * clipArray.length)];
var clip:MovieClip = new pickClip();
addChild(clip);
clip.x = 158;
clip.y = 158;
var tweenFadeOut:Tween = new Tween(clip, "alpha", None.easeOut, 1, 0, 12, true);
}
Copy link to clipboard
Copied
you linkage id's are strings, not objects. so, you must use:
var clipArray:Array=['One','Two',etc..];
to create an object from a string, use getDefinitionByName().
var C:Class;
var clipsOnstage:Array = [];
var clip:MovieClip;
for(var i:int=0;i<clipArray.length;i++){
C=Class(getDefinitionByName(clipArray));
clip=new C();
clip.name = 'mc_'+i;
addChild(clip);
clip.x=
clip.y=
clipsOnstage.push(clip);
}
// now start your fading
[moved from Adobe Creative Cloud to ActionScript 3]
Copy link to clipboard
Copied
Thanks for the quick response! I should probably add that I was mimicking the textbook which named its movieclips Basket, Apple, Orange, Pear, Banana, and such rather than Basket_mc, Apple_mc, Orange_mc, etc. I don't know if that makes any difference, but that's why I just named mine One, Two, Three, etc.
I changed the coding to the below and got an error 1084 for line 10 (expecting identifier before colon).
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.media.Camera;
//Create an array of the 10 movie clips.
var clipArray:Array = new Array ('One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten');
var C:Class;
var:clip:MovieClip;
//Add the clips to the stage at a random order, one by one, until all 10 (and only 10) are on the stage.
for (var i:int = 0; i < clipArray.length; i++) {
C=Class(getDefinitionByName(clipArray));
clip=new C();
clip.name = 'mc_'+i;
addChild(clip);
clip.x = 158;
clip.y = 158;
clipsOnstage.push(clip);
}
var tweenFadeOut:Tween = new Tween(clip, "alpha", None.easeOut, 1, 0, 12, true);
Do I need to rename all the movieclips symbols in my library and in the linkage the traditional way (One_mc)?
Copy link to clipboard
Copied
var:clip:MovieClip;
should be
var clip:MovieClip;
Copy link to clipboard
Copied
It's this one:
var:clip:MovieClip;
which probably wants to be:
var clip:MovieClip;
This particular error shows up in the Compiler Errors panel, and you can double-click on the entry to go to the line of code that has the problem.
Copy link to clipboard
Copied
You can do like kglad said, or make your array contain actual clip references like so:
var clipArray:Array = new Array (new One(), new Two(), etc...);
Copy link to clipboard
Copied
I tried this changing the coding to the following and got error 1180 on line 6 (call to a possible undefined method newOne...).
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Create an array of the 10 movie clips.
var clipArray:Array = new Array (newOne(),newTwo(),newThree(),newFour(),newFive(),newSix(),newSeven(),newEight(),newNine(),newTen());
//Create an array of the movie clips on the stage.
var clipsOnstage:Array = new Array();
//Add the clips to the stage at a random order, one by one, until all 10 (and only 10) are on the stage.
for (var i:int = 0; i < 10; i++) {
var pickClip = clipArray[int(Math.random() * clipArray.length)];
var clip:MovieClip = new pickClip();
addChild(clip);
clip.x = 158;
clip.y = 158;
var tweenFadeOut:Tween = new Tween(clip, "alpha", None.easeOut, 1, 0, 12, true);
}
I'll keep checking the web to see if I can find a solution. Thanks for working on this with me!
Copy link to clipboard
Copied
You need spaces after the word new. Like:
var clipArray:Array = new Array (new One(),new Two(),new Three(),new Four(),new Five(),new Six(),new Seven(),new Eight(),new Nine( ),new Ten());
and for that example your movieclips in the Library would set to shared and have a linkage name of One, Two, Three, etc.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now