PDA

View Full Version : Trying to scale a drag-and-drop movieclip



megawinks
September 14th, 2009, 12:20 AM
Hi there,

I'm trying to create this drag and drop sequence where the "temperature_small" movie clip is dragged and dropped onto a spot on the stage. I've got the drag and drop part of the ActionScript ready, but the trouble comes when I want to re-size the movieclip to make it smaller, I keep getting the error code:


Scene 1, Layer 'ActionScript 3.0', Frame 13, Line6
1180: Call to a possibly undefined method tween.
new tween(temperature_small,"_scaleX",Regular.easeNone,1,0.5,1,false);

and

Scene 1, Layer 'ActionScript 3.0', Frame 13, Line6
1120: Access of undefined property Regular.
new tween(temperature_small,"_scaleX",Regular.easeNone,1,0.5,1,false);

*And I've got a similar one for Line7 as well*I understand this to mean that I've got "_scaleX" and the "Regular.easeNone" parts wrong. I've tried many combinations, but the compiler keeps throwing up the same error messages. What should be the correct code?

Here's the ActionScript that I'm using:

stop();

temperature_small.addEventListener(MouseEvent.MOUS E_DOWN,dragTemperature);
function dragTemperature(myevent:MouseEvent):void {
temperature_small.startDrag(true);
new tween(temperature_small,"_scaleX",Regular.easeNone,1,0.5,1,false);
new tween(temperature_small,"_scaleY",Regular.easeNone,1,0.5,1,false);
}
temperature_small.addEventListener(MouseEvent.MOUS E_UP, dropTemperature);
function dropTemperature(myevent:MouseEvent):void {
temperature_small.stopDrag();
}Thanks!

Cutless009
September 14th, 2009, 12:35 AM
dont you need a variable for your tween?

like


tempTweenX:Tween = new Tween(temperature_small,"_scaleX",Regular.easeNone,1,0.5,1,false);
tempTweenY:Tween = new Tween(temperature_small,"_scalleY",Regular.easeNone,1,o.5,1,false);


and then call them in your function?


also it looks to me from those errors like you havn't imported the tweening classes:

import fl.transitions.Tween;
import fl.transitions.easing.*;

which come with CS3, but I dont think you can access them from Flex for some reason...

megawinks
September 14th, 2009, 02:30 AM
Hey thanks, Cutless009!

I re-wrote the code into:

stop();

import fl.transitions.Tween;
import fl.transitions.easing.*;

var tempTweenX:Tween;
var tempTweenY:Tween;

temperature_small.addEventListener(MouseEvent.MOUS E_DOWN,dragTemperature);
function dragTemperature(myevent:MouseEvent):void {
temperature_small.startDrag(true);
tempTweenX:Tween = new tween(temperature_small,"_scaleX",Regular.easeNone,1,0.5,1,false);
tempTweenY:Tween = new tween(temperature_small,"_scaleY",Regular.easeNone,1,0.5,1,false);
}
temperature_small.addEventListener(MouseEvent.MOUS E_UP, dropTemperature);
function dropTemperature(myevent:MouseEvent):void {
temperature_small.stopDrag();
}And got these error messages:

1180: Call to a possibly undefined method tween.
1119: Access of possibly undefined property easeNone through a reference with static type Class.
1188: Illegal assignment to class Tween.Was my code wrong?
Anyway I tried the following code and it worked as I had wanted it to. Decided to direct the scaling onto the movieclip itself, and realized the scale function was "scaleX" instead of "_scaleX" and so yeah, but thanks for steering me in the right direction!


stop();

temperature_small.addEventListener(MouseEvent.MOUS E_DOWN,dragTemperature);
function dragTemperature(myevent:MouseEvent):void {
temperature_small.startDrag(true);
temperature_small.scaleX = 0.5;
temperature_small.scaleY = 0.5;
}
temperature_small.addEventListener(MouseEvent.MOUS E_UP, dropTemperature);
function dropTemperature(myevent:MouseEvent):void {
temperature_small.stopDrag();
}

Felixz
September 14th, 2009, 06:32 AM
Use Tween, not tween.

megawinks
September 17th, 2009, 12:32 AM
Oh! Thanks!