|
-
Translation from 2.0 to 3.0
I'm fairly new to 3.0 and know zero 2.0. As I searched around for some info on how to get something done (basically I have a scene of a farm on screen, when user clicks on an animal, the animal button or (movieclip inside button) "zooms" or enlarges and centers on the screen, makes animal sound and goes back to original position.
Well, I found this, which I believe would be a method that works ... but it's in Actionscript 2.0 and am having a hell of a time translating it to AS 3.0. I tried to set up an event listener on the button that sets off a conditional function increasing xscale and yscale as long as it's under the desired size (350). Anyway, it's not working. Here's the 2.0 actionscript I found here on flashkit. Wondering if anyone has any tips on how to translate.
button.onPress = function() {
var yourpic:MovieClip = _root.blabla;
var maxwidth:Number = 400; // The width of the enlarged picture
var maxheight:Number = 400; // The height of the enlarged picture
var speed:Number = 2;
this.onEnterFrame = function() {
if (yourpic._yscale < maxheight) {
yourpic._yscale += speed;
}
else {
...... etc etc.
}
}
There is also a great tutorial showing this code (even simpler method, though it seems incomplete) - clearly easy stuff, but I'm not seeming incapable of translating to AS 3.0:
stop();
this.onEnterFrame = function(){
if(zoom == true){
prevFrame();
}
}
this.onRollOver = function(){
zoom = false;
play();
}
this.onRollOut = function(){
zoom = true;
}
Last edited by Leftyplayer; 08-11-2009 at 05:08 PM.
-
lemon juice hurts your eyes
PHP Code:
button.addEventListener(MouseEvent.CLICK, clickHandler); var yourpic:MovieClip = MovieClip(root).blabla; // if code is on main timeline, drop the root part and just call for blabla var maxwidth:Number = 400; // The width of the enlarged picture var maxheight:Number = 400; // The height of the enlarged picture var speed:Number = 2; var zoom:Boolean = false;
function clickHandler(e:MouseEvent):void { addEventListener(Event.ENTER_FRAME, scaleUp); if(!zoom) zoom = true; else zoom = false; }
function scaleUp(e:Event):void { if(zoom && yourpic.scaleY < maxHeight) yourpic.scaleY += speed; else { // to reverse, just remove the line below removeEventListener(Event.ENTER_FRAME, scaleUp); // and take this line out of comments // yourpic.scaleY -= speed; } }
One thing though, a scale of 400 will stretch that bad boy out really bad! At a regular size, both scaleX and scaleY are 1, so * 400 will give a really pixelated picture (if that's what your using).
Also, I see your only using scaleY, and to have a equal proportion scaling, you should use the scaleX property too!
Last edited by florianvanthuyn; 08-11-2009 at 05:20 PM.
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
-
Thank you, Florian. I will go give it a try.
FYI, I'm using a vector illustration so it stretches well.
-
Just tested it and it's giving me this error - possibly something I'm doing wrong on my end.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ZoomEffectTest_fla::MainTimeline/scaleUp()
I've double-checked my object and it's adequately labeled and given an instance name, as well as linked for AS usage. I'm wondering if the problem is that I have the movieclip inside the button ... could that cause an issue?
-
lemon juice hurts your eyes
Wait, do you mean that the MovieClip you're scaling also functions as the button?
Or is the MovieClip inside of another MovieClip that you use as a button?
Or is it inside of a Button symbol (which has the 4 button states)?
I'll try to help you when one of those questions get answered, because now I can keep on guessing
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
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
|