Skip to main content
October 16, 2009
Answered

Scroll movie clip left and right

  • October 16, 2009
  • 2 replies
  • 5550 views

I am wanting to make a scroller similar to the Flash Components 360PanVeiwer http://www.flashloaded.com/flashcomponents/360panviewer/example2.html but I have no idea about how I can go about doing it. Could someone please explain how i might acheive this in AS3 alo I don't nessesarily need it to be 360 I just want to be able to scroll through a movie clip that is much bigger than my stage and click on the buttons in side the clip. I hope that makes sence.

This topic has been closed for replies.
Correct answer kglad

if mc is the movieclip with left edged registration point that you want to scroll based on mouse position, you can use:

var tl:MovieClip=this;

paramF(mc,0,0,stage.stageWidth,stage.stageWidth-mc.width);

tl.addEventListener(Event.ENTER_FRAME,scrollF);

function scrollF(e:Event){

mc.x=mc.m*tl.mouseX+mc.b;

}

function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){

mc.m=(y1-y2)/(x1-x2);

mc.b=y1-mc.m*x1;

}

2 replies

November 6, 2009

Ok well I got it all running nicely now. The slider fits like it should and instead of using to movies I created a movie clip for the intro animation and the from that loaded the slider into my proLdr.

I just have one last queastion. how can I get rid of this error?


TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at shop_fla::MainTimeline/scrollF()

it oviously has issues with unloading a null object (what ever that is) from that movie.

stage.addEventListener(Event.RESIZE, resizeHandler);
stage.dispatchEvent(new Event(Event.RESIZE));

function resizeHandler(event:Event=null):void {
    var sw:Number = stage.stageWidth;
    var sh:Number = stage.stageHeight;
    paramF(mc,0,0,sw,sw-mc.width);
}

resizeHandler(null);     // I think this is what it needs to unload.
var tl:MovieClip=this;

paramF(mc,0,0,stage.stageWidth,stage.stageWidth-mc.width);

tl.addEventListener(Event.ENTER_FRAME,scrollF);

function scrollF(e:Event){

mc.x=mc.m*tl.parent.parent.mouseX+mc.b;

}

function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){

mc.m=(y1-y2)/(x1-x2);

mc.b=y1-mc.m*x1;

}

I am unloading the movie using:

aboutBtn.addEventListener(MouseEvent.CLICK, aboutLoad);
function aboutLoad(e:MouseEvent):void {
    ldr.unload();
    ldr.source = "about.swf";
}

kglad
Community Expert
Community Expert
November 6, 2009

use:


aboutBtn.addEventListener(MouseEvent.CLICK, aboutLoad);
function aboutLoad(e:MouseEvent):void {

tl.removeEventListener(Event.ENTER_FRAME,scrollF);
    ldr.unload();
    ldr.source = "about.swf";
}

November 6, 2009

I tried it out and it said that tl was undefined and couldnt be accessed and the same with scrollF. Proberly because I am trying to do it in my main movie and I guess unless tl or ScrollF has been accessed previously they don't exsit and are underfined. Can I use some kind of if statement?(not that I know how to do that.)

kglad
Community Expert
Community Expert
October 16, 2009

what causes the movieclip to scroll?  mouse position?  button clicks?  something else?

October 16, 2009

I think it would proberly have to be drag in order to click on the buttons inside the MC nicly. But rollover would be cooler provided that the buttons worked properly.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
October 16, 2009

if mc is the movieclip with left edged registration point that you want to scroll based on mouse position, you can use:

var tl:MovieClip=this;

paramF(mc,0,0,stage.stageWidth,stage.stageWidth-mc.width);

tl.addEventListener(Event.ENTER_FRAME,scrollF);

function scrollF(e:Event){

mc.x=mc.m*tl.mouseX+mc.b;

}

function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){

mc.m=(y1-y2)/(x1-x2);

mc.b=y1-mc.m*x1;

}