Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Actionscript to trigger horizontal movement of a movie clip.

Hi

I have just began work on a flash site for which i need some assistance with the actionscript.

The main mc consists of a landscape painting that is about 600 px high and about 1900 px wide, it fits my 24" imac screen.

The main mc will be centered and On most browsers the main area shown will obvously only be a section in the middle of th mc.

I want to add action script to the mc which takes moves the clip left and right when the user moves their mouse into the left and right hand sides of the screen. The area needs to be about 1/4 of 1/5 of the screen on each side.

Can anyone help??

Many thanks
--s--
0
socross
Asked:
socross
  • 3
  • 3
1 Solution
 
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Try the following code:

<code snippet>

mymc refers to the instance name of your own MovieClip; just replace it and you're set.

-V
stageWidth=550;
stageHotSpot=stageWidth/4;
mymc.onEnterFrame = function() {
	if((_xmouse>0)&&(_xmouse<stageHotSpot)) {
		this._x++;
	} else if((_xmouse<stageWidth)&&(_xmouse>(stageWidth-stageHotSpot))) {
		this._x--;
	}
}

Open in new window

0
 
socrossAuthor Commented:
Hi

Just to check, the stage will useually be wider that the screen, so the trigger areas need to be 1/4 the size of the screen on the on the lefthand side and right hand sides.

Is this good??

-s-
0
 
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Yeah, that's why I dropped the variables stageWidth, that you need to modify from 550 to whatever size your movie is, and stageHotSpot which is exactly doing that, it divides the total width of the stage by 4 (you can also change it to 5 or whatever seems better).

Good luck.

-V
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
socrossAuthor Commented:
hi

have tried with your code but not getting the effect i want, have tried modifying it to work but just cant get it right.

You can see from my code snippet that i need the mc to move left and right respectively when the mouse goes over the left and right quaters of the screen.

Im not sure im getting the function structure right, would i need to use a listerner to check when the stage is resized so it can recalculate the width.

Any ideas???

--s--
main.onEnterFrame = function() {
		if((_xmouse>0)&&(_xmouse<(Stage.width/4))) {
                main._x++;
        } else if((_xmouse<Stage.width)&&(_xmouse>(Stage.width-(Stage.width/4)))) {
                main._x--;
        }
}

Open in new window

0
 
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Mhh, it should be working like that. Can you send me the *.fla file? It might be easier to look at it rather than just speculate.

My e-mail is on my profile

-V
0
 
socrossAuthor Commented:
ok will do, forgot to bring it home with me but will upload it tomorrow afternoon, We have got it sort of working, it probably just needs some tweaks!!!

Many thanks

--s--
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now