AS2 Add more movieclips to var
AS2 Add more movieclips to var
This question may be weird, but it's a big problem for me.
onClipEvent (load) {
var ground:MovieClip = _root.bottomground1;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 10;
var maxJump:Number = -17;
var touchingGround:Boolean = false;
}
So, the thing i want to do is to add more movieclips to var ground, such as
var ground:MovieClip = _root.bottomground1,_root.bottomground2...;
I tried this also:
var ground:MovieClip = _root.bottomground1, MovieClip = _root.bottomground2...;
None of it is working. Any reply would be very helpful.
1 Answer
1
A variable can only have one value :) What you need is an array. Might not be a valid AS2, it's been a while:
Create an array:
var groundArray:Array = new Array(_root.bottomground1, _root.bottomground2);
OR something like
// add objects with instance names bottomground1 to bottomground9
var groundArray:Array = new Array();
for(var i:int = 1; i < 10; i++)
{
groundArray.push(_root[(bottomground + i)]);
}
Read from your array:
var myGroundMC:MovieClip = groundArray[0] as MovieClip; // first object in array
OR
// Loop trough all objects and do something
for(var i:int = 0; i < groundArray.length; i++)
{
var myGroundMC:MovieClip = groundArray[i] as MovieClip;
// do something with it
}
So what code is on this line ? Just spotted an error in my code, should be groundArray.push(_root[("bottomground" + i)]);
– Philarmon
Mar 8 '16 at 8:15
Hello! I found out how to make working arrays, but still i can't make that flash recognize them as MovieClips. var ground:Array = new Array("_root.classicground2", "_root.classicground1", "_root.biggerground1", "_root.bigground1") as MovieClip;
– Stefan Đorđević
Mar 8 '16 at 13:36
No, you don't need "" here, this would make an array of strings and you want an array of movieclips, so it should be just var groundArray:Array = new Array(_root.bottomground1, _root.bottomground2);
– Philarmon
Mar 9 '16 at 12:40
I fixed that. There are no errors, but it still doesn't work, i don't know why :/ Download my .FLA: sendspace.com/file/couaec I hope you could fix this :(
– Stefan Đorđević
Mar 11 '16 at 23:45
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I am getting this error: Scene=Scene 1, layer=Ground, frame=4, Line 3 Syntax error.
– Stefan Đorđević
Mar 7 '16 at 18:02