# AS2 code to AS3

**URL:** <https://forum.kirupa.com/t/as2-code-to-as3/262208>\
**Category:** flash\
**Created:** [June 4, 2008, 5:33am UTC](https://forum.kirupa.com/t/as2-code-to-as3/262208 "2008-06-04T05:33:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coljung](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@coljung](https://forum.kirupa.com/u/coljung)\
**Post date:** [June 4, 2008, 5:33am UTC](https://forum.kirupa.com/t/as2-code-to-as3/262208/1 "2008-06-04T05:33:24Z")

</div>

Well i began using flash a few months ago after a couple of years of not using it. I’ve been trying to catch up with Actionscript but its proving quite hard.

Now im trying to work out a gallery, which i had working with AS2, but now i had to make the thumbs move though mouse events and did it with AS3, as i want to start coding everything with it.

The problem is that the code i had for the gallery needs to be updated but im not that knowledgeable of AS3 yet.

Here’s how the gallery code looks now with AS2:

```auto
var myDropShadowFilterOver = new DropShadowFilter (1,62,0x000000,1,10,10,1,1,false,false,false);
var myDropShadowFilterOut = new DropShadowFilter (1,62,0x000000,0,10,10,1,1,false,false,false);

this.createEmptyMovieClip("images", 100);
this.attachMovie("mask", "mask", 101);
mask._x =6;
mask._y = 132;
target =-130;
images.setMask(mask);
images._y = 132;
images._x = 100;
speed = 9;

for (var i = 0; i<14; i++) {
    var img = images.attachMovie("image"+i, "image"+i, i); 
    img._x = img._width*i;
    
    var thumb = this.myThumbs_mc["thumb"+i];
    thumb._alpha = 90;
    thumb.pos = target+(i*-img._width);
    
    thumb.onPress = function() {
        target = this.pos;
    };
    thumb.onRollOver = function() {
        this._alpha = 100;
        this.filters = [myDropShadowFilterOver];
    };
    thumb.onRollOut = function() {
        this._alpha = 90;
        this.filters = [myDropShadowFilterOut];
    };
}

```

And this is how i have it so far:

```auto
var myDropShadowFilterOver = new DropShadowFilter (1,62,0x000000,1,10,10,1,1,false,false,false);
var myDropShadowFilterOut = new DropShadowFilter (1,62,0x000000,0,10,10,1,1,false,false,false);

var myMask:Shape = new Shape();
myMask.graphics.beginFill(0xFFFFFF);
myMask.graphics.drawRect(6,6,960,389);
addChild(myMask);

var images=new MovieClip();
stage.addChild(images);

var target:Number =-130;

images.mask=myMask;
trace("i");
images.y = 132;
images.x = 100;
var speed:Number = 9;

for (var i = 0; i<14; i++) {
    
    var img = images.attachMovie("image"+i, "image"+i, i); 
    img.x = img.width*i;
    var thumb = this["thumb"+i];
    trace (this["thumb"+i]);
    thumb.alpha = 90;
    thumb.pos = target+(i*-img.width);
    
    thumb.onPress = function() {
        target = this.pos;
    };
    thumb.onRollOver = function() {
        this.alpha = 100;
        this.filters = [myDropShadowFilterOver];
    };
    thumb.onRollOut = function() {
        this.alpha = 90;
        this.filters = [myDropShadowFilterOut];
    };

```

I’m stuck on \*\*var img = images.attachMovie(“image”+i, “image”+i, i);  
\*\*And i don’t know if i have problems somewhere else, every time i fix a line, i get a new problem each time.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![unformatt](https://avatars.discourse-cdn.com/v4/letter/u/58956e/32.png) [@unformatt](https://forum.kirupa.com/u/unformatt)\
**Post date:** [June 4, 2008, 1:49pm UTC](https://forum.kirupa.com/t/as2-code-to-as3/262208/2 "2008-06-04T13:49:21Z")

</div>

attachMovie is no longer used in AS3. In AS3, you just create a new MovieClip like any other class (e.g. mc = new MovieClip()). Do a search, there are plenty of tutorials about this.

---

<div class="post-metadata">

**Author:** ![coljung](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@coljung](https://forum.kirupa.com/u/coljung)\
**Post date:** [June 4, 2008, 3:02pm UTC](https://forum.kirupa.com/t/as2-code-to-as3/262208/3 "2008-06-04T15:02:42Z")

</div>

thanks , although i’ve done some research im still a bit confused.

for example, i have to use new MovieClip() even though they are already in my library ? also how could i add their names accordingly to the variable “i” with its respective instance names ? this is the part where i got stuck.

for the moment i found a way to do it all with as2, i have a deadline and will have to do it the easiest way now, although i would have preferred to have it all with as3.

i’ll look for the tutorials in any case.

thanks

---

<div class="post-metadata">

**Author:** ![unformatt](https://avatars.discourse-cdn.com/v4/letter/u/58956e/32.png) [@unformatt](https://forum.kirupa.com/u/unformatt)\
**Post date:** [June 4, 2008, 3:24pm UTC](https://forum.kirupa.com/t/as2-code-to-as3/262208/4 "2008-06-04T15:24:59Z")

</div>

In the library you can specify a Class instead of a Identifier. Then you could say

```auto
var img = new MyImage();

```

except since you are doing it dynamically, its a little more complicated. You’ll have to dynamically get the Class’s constructor:

```auto
import flash.utils.getDefinitionByName;
var imgClass:Class = getDefinitionByName('MyImage'+i) as Class;
img = new imgClass();

```
