質問

I am completing an online tutorial and manipulating it suit my website. I've come across this code...

`// Create a menu item movie clip in the menu_mc instance on the main timeline
            // for each item element offsetting each additional further down the screen

var item_mc = menu_mc.attachMovie("movieitem","item"+item_count, item_count);
            item_mc._x = item_count * item_spacing;
            item_count++;`

The following line gives me a problem (the method is no longer supported)

var item_mc = menu_mc.attachMovie("movieitem","item"+item_count, item_count);

How can i achieve this?

I've tried the following with no joy. message too many arguments?

var mItem:movieitem = new movieitem;
var item_mc = menu_mc.addChild(mItem,mItem+item_count, item_count);
役に立ちましたか?

解決

addChild() only accepts 1 argument, which is the display object itself. Also, it looks like you're missing brackets when you create your object and by convention, class names are capitalised.

var mItem:movieitem = new movieitem();

Edit based on my comment

Looking at the documentation for attachMovie() for AS2 (wow, been awhile since I've looked at this), it takes in 3 arguments:

id:String, name:String, depth:Number

Now the id is used to grab a movieclip from the library. This is no longer needed as you've already created a movieclip object from your library in the line before:

var mItem:Movieitem = new Movieitem();

The second argument name is used to create a unique instance name for the created moviclip from the library. You don't really need this. In the line where you create the movieclip (see above), you already have a unique reference you can use to access the movieclip. Interestingly, attachMovie() also returns a reference -I've never ever found a use for the instance names given with the 'name' argument. I just use the reference returned to access it, which you are already doing.

The third argument depth determines which depth the movieclip is placed at. In your case, I am guessing that ' item_count' is just a number that increases, which effectively puts that movie clip at the highest depth when that line is executed. By default, addChild() will automatically do this for you and put the display object (your movieclip) at the highest depth within the parent at the time it is added. So, unless you wanted it at a specific depth/overlapping order, you don't really need to pass this in either. If you did want to add something at a specific depth, look at addChildAt()

Hence as mentioned before, you can just pass in the reference to your movieclip/display object in to addChild().

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top