-
Can anyone help convert this AS2 code to AS3?
Hello I followed a tutorial to set up a scrolling gallery (http://www.webdesignerwall.com/tutor...#comment-39258) and it works great. Unfortunately it is written in AS2, which I am not familiar with. I have attempted to convert it to AS3 but it doesn't work. Could anyone help me out with the conversion of this code?
stageWidth = Stage.width;
speed1 = 15;
speed2 = 14;
mc1Width = front_mc._width;
mc2Width = back_mc._width;
mc1X = front_mc._x;
mc2X = back_mc._x;
lock_scroll = false;
_root.onEnterFrame = function () {
if (!lock_scroll)
scroll_mc();
}
function scroll_mc() {
var xdist = _xmouse-(stageWidth/2);
mc1X += -xdist/speed1;
mc2X += -xdist/speed2;
if (mc1X>=0) {
mc1X = 0;
}
if (mc1X<=stageWidth-mc1Width) {
mc1X = stageWidth-mc1Width;
}
if (mc2X>=0) {
mc2X = 0;
}
if (mc2X<=stageWidth-mc2Width) {
mc2X = stageWidth-mc2Width;
}
setProperty("front_mc", _x, mc1X);
setProperty("back_mc", _x, mc2X);
}
createEmptyMovieClip("content_box", 200);
content_box._x = 195;
content_box._y = 92;
-
anyone else hear that?
Give this a shot:
Code:
var stageWidth:Number=stage.stageWidth;
var speed1:Number=15;
var speed2:Number=14;
var mc1Width:Number=front_mc.width;
var mc2Width:Number=back_mc.width;
var mc1X:Number=front_mc.x;
var mc2X:Number=back_mc.x;
var lock_scroll:Boolean=false;
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
if (! lock_scroll) {
scroll_mc();
}
}
function scroll_mc() {
var xdist = mouseX-(stageWidth/2);
mc1X+=- xdist/speed1;
mc2X+=- xdist/speed2;
if (mc1X>=0) {
mc1X=0;
}
if (mc1X<=stageWidth-mc1Width) {
mc1X=stageWidth-mc1Width;
}
if (mc2X>=0) {
mc2X=0;
}
if (mc2X<=stageWidth-mc2Width) {
mc2X=stageWidth-mc2Width;
}
front_mc.x=mc1X;
back_mc.x=mc2X;
}
var content_box:MovieClip = new MovieClip();
content_box.x=195;
content_box.y=92;
addChild(content_box);
Hope that helps!
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
-
Thank you very much, that works great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|