|
| Nicolas Parziale |
Post
#1
|
|
Member Group: Members Posts: 22 Joined: 22-June 06 Member No.: 46 |
hi, first of all, congratulations for Sandy !
i started doing some easy tests with Sandy, and i got stuck on the object events , can you please give me some help on how to use them, i mean, how to run a function after an object is clicked, sorry about my english but i'm argentinian, ha, the next world champions !hahha thanks for sandy, byeee hope you can help me soon ! |
| kiroukou |
Post
#2
|
|
Administrator Group: Root Admin Posts: 930 Joined: 12-June 06 Member No.: 1 |
Hi Nicolas,
Yes an example of this events use is missing. I'm going to write a tutorial about that, but I've written the example to help you right now. CODE import sandy.core.data.Vector; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.Ease; import sandy.core.transform.*; import sandy.events.*; import com.bourre.events.BasicEvent; /** * @mtasc -main CubeRotationTest -swf CubeRotationTest.swf -header 300:300:120:FFFFFF -version 7 -wimp */ class CubeRotationTest { private var _mc : MovieClip; private var _fps:Number; private var _t:Number; private var _t2:Number; private var _pause:Boolean; private var rotint:RotationInterpolator; public function CubeRotationTest( mc:MovieClip ) { _mc = mc; _mc.createTextField('fps', 10000, 0, 20, 50, 20 ); World3D.getInstance().addEventListener( World3D.onRenderEVENT, this, __refreshFps ); _t = _t2 = getTimer(); _fps = 0; _pause = false; __start(); } private function __refreshFps ( e:BasicEvent ):Void { var t:Number = getTimer(); _t2 = t; _fps ++; if( (t-_t) >= 1000 ) { _mc.fps.text = _fps+' ips'; _t = getTimer(); _fps = 0; } } public static function main( mc:MovieClip ) : Void { if( !mc ) mc = _root; var c:CubeRotationTest = new CubeRotationTest( mc ); } private function __start ( Void ):Void { var w:World3D = World3D.getInstance(); w.setRootGroup( __createScene() ); __createCams(); w.render(); } private function __createCams ( Void ):Void { var mc:MovieClip;var cam:Camera3D;var screen:ClipScreen; mc = _mc.createEmptyMovieClip( 'screen', 1 ); screen = new ClipScreen( mc, 300, 300 ); cam = new Camera3D( 700, screen ); World3D.getInstance().addCamera( cam ); } private function __createScene ( Void ):Group { var bg:Group = new Group(); // -- interpolator var myEase:Ease = new Ease(); // var tgRotation:TransformGroup; var tgTranslation:TransformGroup; tgRotation = new TransformGroup(); tgTranslation = new TransformGroup(); // var translation:Transform3D = new Transform3D(); translation.translate( 0, 0, 500 ); tgTranslation.setTransform( translation ); // rotint = new RotationInterpolator( tgRotation, myEase.create(), 500 ); // -- listener rotint.addEventListener( BasicInterpolator.onEndEVENT, this, __yoyo ); rotint.addEventListener( BasicInterpolator.onProgressEVENT, this, __playMouse ); // -- earth var box:Box = new Box( 50, 50, 50, 'quad' ); var skin:Skin = new MixedSkin( 0xFF0000, 100, 0x0, 50, 2 ); skin.setLightingEnable( true ); box.setSkin( skin ); // IMPORTANT PART // we enable the events on that object box.enableEvents( true ); box.addEventListener( ObjectEvent.onPressEVENT, this, __onClick ); // tgRotation.addChild( rotint ); tgRotation.addChild( box ); tgTranslation.addChild( tgRotation ); bg.addChild( tgTranslation ); // return bg; } private function __yoyo( e:InterpolationEvent ):Void { e.getTarget().redo(); } private function __onClick():Void { if( !_pause) { rotint.pause(); _pause = true; } else { rotint.resume(); _pause = false; } } private function __playMouse( e:InterpolationEvent ):Void { var difX:Number = 150 - _mc._xmouse; var difY:Number = 150 - _mc._ymouse; var dist:Number = Math.sqrt( difX*difX + difY*difY ); RotationInterpolator(e.getTarget()).setAxisOfRotation( new Vector( -difY, difX, 0 ) ); RotationInterpolator(e.getTarget()).setDuration( 10000 / dist ); } } This peace of code makes the cube rotating and stopping if you click on it. Have fun. Hope it helps. Thomas |
| kiroukou |
Post
#3
|
|
Administrator Group: Root Admin Posts: 930 Joined: 12-June 06 Member No.: 1 |
Hope to find why the [code]tag means php very soon :S ....
I move this topic in the appropriate room |
| Nicolas Parziale |
Post
#4
|
|
Member Group: Members Posts: 22 Joined: 22-June 06 Member No.: 46 |
HI, thanks for the example, but the flash tells me:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 14: Classes may only be defined in external ActionScript 2.0 class scripts. class CubeRotationTest i'm pretty sure i'm pasting your code somewhere i should'nt be and again, could you please help me ? |
| Nicolas Parziale |
Post
#5
|
|
Member Group: Members Posts: 22 Joined: 22-June 06 Member No.: 46 |
hi, me again, i could solve the problem, thanks again !!!!, please more tutorials on how to use this great work you've done !!!
i'm gonna start a fan club of sandy's developers, you're great guys ! esto en español: son unos genios !!! |
| Mnyh |
Post
#6
|
|
Member Group: Members Posts: 28 Joined: 22-June 06 Member No.: 45 |
hi people, u also help me with this event-stuff (IMG:style_emoticons/default/wink.gif)
thanx! |
| kiroukou |
Post
#7
|
|
Administrator Group: Root Admin Posts: 930 Joined: 12-June 06 Member No.: 1 |
You are welcome.
Do not hesitate to post your stuff if you agree to share it. More examples we have, easier it will be to beginners to learn the API. I'll publish my others samples soon. Have fun (IMG:style_emoticons/default/smile.gif) |
| Lo-Fi Version | Time is now: 20th August 2007 - 12:14 PM |