Solved

Actionscript to trigger horizontal movement of a movie clip.

Posted on 2007-12-05
6
334 Views
Last Modified: 2008-11-23
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
Comment
Question by:socross
  • 3
  • 3
6 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 20416130
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
 
LVL 1

Author Comment

by:socross
ID: 20416332
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
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 20417245
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:socross
ID: 20418840
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
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 20420791
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
 
LVL 1

Author Comment

by:socross
ID: 20422710
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Software Restriction Policy 8 856
Video sharing with user login 3 198
Failed download 57 552
Converting CFGRID from Flash to HTML in Coldfusion 1 90
This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now