Now, I had a few ideas on how I would approach the problem: 1) I could apply a mask over the picture so that a portion of the picture would show at a time, or 2) I could have the image move as the mouse moved; this way the picture would always stay in the main view of the stage. I tried both methods and I would have to say the second method works the best. The first method requires more steps, whereas the second method requires a few lines of code.
I was inspired by this code that I found in the actionscript forum. However, this particular post only focused on as2; my code needed to be in as3. So I took the basis of the code and I changed it around so that it will work for my project. You're probably wondering how to actually set everything up in Flash. The following paragraphs list the steps that I took to reach my end result. Keep in mind, this isn't the best way of achieving this, but it is one way:
Step 1: Import a picture (or create a vector graphic) that is larger than your stage size. For instance, my image is 800x1066 and my stage size is 480x800.
Step 2: Convert your image into a MovieClip and name your MovieClip in the properties panel. For my project, I named it MovieClipName, but you can name it whatever you want.
Step 3: Align you picture to the top left of your stage. Use the Align tab for precision.
Step 4: On a new layer, copy and paste the following in actions panel:
var myTimer:Timer = new Timer(100); // 1 second
//Add the timer event
myTimer.addEventListener(TimerEvent.TIMER, CheckMouse);
function CheckMouse(event:TimerEvent):void{
//Specify your MCs X and Y position as the mouse moves
MovieClipName.x = (stage.mouseX / stage.stageWidth) * ( MovieClipName.width - stage.stageWidth) * -1;
MovieClipName.y = (stage.mouseY / stage.stageHeight) * ( MovieClipName.height - stage.stageHeight) * -1;
}
Step 5: Publish your document (CTRL+enter)//Starts timer
myTimer.start();
You should now have a panning image (it takes a few minutes to load). Be creative, you can do quite a lot with this technique.
Dee again...
ReplyDeleteThis is awesome! I think I might have to try this one. Do you find AS3 easier than AS2? I have only worked in AS2 and I still own CS4.
Cool stuff! Nice tut!
I honestly can't say that AS3 is easier than AS2. What I can say is that AS3 offers a lot more capabilities.
ReplyDeleteCheck this link out for more info:
http://www.bannersnack.com/blog/advantages-of-as3-vs-as2-why-should-google-adwords-accept-actionscript-3-banners/