Hi Beno,
Okay - I tried to use the FLA you posted, but don't have CS4, so I can't
open it, but I have got my example to run okay.
That's probably the limit of my generosity for now as I am going to be
too busy to help over the next few days and now it's your turn :)
So please digest some of the stuff in the code and look in the AS3
documentation for MovieClip about it's Events like ADDED_TO_STAGE,
ENTER_FRAME, etc. to get more of a grasp on how these things might work.
The Events stuff is all over the place in AS3 - not so much in
PHP/Python land (unless you are familiar with callbacks =~ events)
because a lot of Web based stuff is "stateless" - you call a URL, your
code calls a load of functions in series and draws you a page,
finished. You should make understanding events stuff a priority in
order to get your head around the style of coding most of us are doing -
it's just like the old on(enterFrame) { trace("hello from " + this") }
or myClip.onRelease = function() { trace("you clicked me") } code from
AS1 / AS2 days, but slightly less forgiving. Admittedly AS3 is a
steeper curve, but you can still write in AS2 style for some stuff -
check out this book / PDF, which is very useful and easy to follow too
https://www.adobe.com/devnet/actionscript/articles/as3_migration_cookbook/as3_migration_cookbook.pdf
I did run the code at the bottom of the email in FlashDevelop - and it
works as I think you intend, but I am not 100% at what you are aiming
at. I commented it to show what I am trying to acheive.
When you say about the "traces" for both sets of code in your last email
- these are not "traces", they are output from the Flash compiler or
Flash player complaining about something. The first one;
at Main2/theThumb()
at Main2/init()
at Main2
is an Exception, which possibly happens because Flash is not ready to do
stuff on stage when Main2() is started. (I added the
Event.ADDED_TO_STAGE handler to hopefully combat this...)
The 2nd error message is from the compiler (look at the panel it appears
in).
Main2.as, Line 28 1136: Incorrect number of arguments. Expected 1.
Google "AS3 #1136" if you don't understand the message - (same for any
error number you don't understand) This one means you are calling a
function with the wrong number of parameters, e.g. gotoAndStop() -
should be gotoAndStop(frameNumber) - look in the "Source" column of the
Compiler Errors panel to tell you more info, but the Line 28 will give
you a big clue as to where you are going wrong - I could not see in your
code because the formatting maybe broken by the email...
package
{
import flash.events.Event;
//import flash.events.ProgressEvent;
import flash.events.Event;
//import flash.events.MouseEvent;
import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.easing.*;
/**
* This class creates a MovieClip called myThumb and then it will
tween the rotation of the MovieClip.
* When the Tween has finished, the class will use an Enter Frame
handler to wait 10 frames before
* repeating the tween. It will do this until the cows come home.
*/
public class Main2 extends MovieClip
{
//I changed this to MovieClip - guessing CloseThumb is a symbol
in your library - change it back if you are happy this code works...
public var myThumb:MovieClip;
private var counter:int = 0;
public function Main2()
{
trace('Main2()');
//It maybe a good idea to wait for the MovieClip to be added
to the stage before starting to do stuff.
//It's also a good idea to always add the last 3 parameters
to the addEventListener function:
//the 3rd is important - it makes Flash more forgiving when
you forget to clean up after yourself.
//Read Moock's book about Event Listeners (in Chapter 12 I
think)
addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true)
}
//You have to have the Event argument for init because it is now
an Event Handler - setup by addEventListener
public function init(e:Event):void
{
trace('Main2::init()');
theThumb();
//We want to start the myThumb clip tweening straight away here.
doTween();
}
public function checkFrame(e:Event):void
{
//If you do your == comparisons this way round - put any
"constant" first, (you can't always do that)
//your compiler will spot the error when you only put one
"=" in - "if(counter = 10)" is always true...
//Otherwise it will run happily and not work...
if (10 == counter)
{
doTween();
counter = 0;
} else
{
counter++;
trace(counter);
}
}
public function doTween():void
{
trace('Main2::doTween()');
//And whilst it is tweening, we don't want to keep doing the
counter loop because it breaks our tweening..
removeEventListener(Event.ENTER_FRAME, checkFrame);
addChild(myThumb);
TweenMax.to(myThumb, .4, {shortRotation:{rotation:60},
ease:Back.easeOut,onComplete:onFinishTween});
}
public function onFinishTween():void
{
trace("Main2::onFinishTween()");
//But when the tween is finished, it's okay to start the
counter checking again
addEventListener(Event.ENTER_FRAME, checkFrame, false, 0, true);
removeChild(myThumb);
}
public function theThumb():void
{
trace('Main2::theThumb');
myThumb = new MovieClip();
myThumb.x = 365;
myThumb.y = 355;
}
}
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders