Actionscript 3 stage.focus?
- Started
- Last post
- 14 Responses
- CyBrain
http://talesfromthehead.com/port…
I have a masked movie clip with a bunch of squares that should TweenLite to a tint on rollover. They trace a rollover message, but don't do the tween until I click anywhere on the stage. This is also the case if I take the squares' movie clip out of the mask.
The first line of my constructor function for the masked object is stage.focus = this;
but that is having no effect.Is there anything I'm missing here?
- CyBrain0
Here's my code for the masked movie clip of squares:
http://pastebin.com/f59842367
- maximillion_0
you should always add a listener in the constructor to listen when the object is added to stage, esp if you want to reference the stage
addEventListener(Event.ADDED_TO... onAddedToStage);
the method:
private function onAddedToStage(e:Event):void {
// code that references the Stage object
}however i dont think this is your problem. does "frame_mc" exist on the first frame of the target? try tracing out a reference to it
- frame_mc is on the first frame of the target and I have gotten that to trace. I will try your eventListener. Thanks.CyBrain
- maximillion_0
the evt obj should be "Event.ADDED_TO_STAGE" QBN shortened the code
- maximillion_0
here's some info on target vs currentTarget for your event objects:
- maximillion_0
you should alos look at destructing your objects too, it will help you keep performance of yr swf looking good
addEventListener(Event.REMOVED_F... , onRemovedFromStage)
the method:
private function onRemovedFromStage(e:Event):void {
// remove all listeners to child objects (your PbtnMC objs etc) within the parent object (this obj) so that they dont take up memory when not needed
}
- acrossthesea0
Unrelated question but, what's the reason for doing the "pBtn.name" stuff for the buttons you create? Since you're doing this all dynamically, would doing something like "pBtn.index = j" not suffice when you needed to track what button was clicked later on for loops and such?
- CyBrain0
The Event.ADDED_TO_STAGE didn't work.
http://pastebin.com/f24f588b9also tried registering frame_mc with the MouseEvents, but still got the same results as before.
My best guess right now is that I should set the stage.focus.
When I traced stage.focus at the end of onAddedToStage or rolling over any of the squares (before clicking anywhere) I got [object Portfolio] as a result. Portfolio.as is my document class.
After clicking anywhere I trace null as stage.focus rolling over any of the squares.
After clicking anywhere I get null as a result.
- CyBrain0
"..would doing something like "pBtn.index = j" not suffice ..."
I got undefined when I tried tracing pBtn_array.index.I always have to resort to some kind of black magic in order to refer to things I want to control. That's where I really miss the efficiency of AS2.
- When this code is all sorted, I'll see if I can help you out w/ some efficiency stuff. It'll be good practice.acrossthesea
- maximillion_0
i dont think this is a focus issue
- CyBrain0
It turns out this is a problem with TweenLite.
If I replace the TweenLite tint functions for over and out with
e.currentTarget.frame_mc.alpha = .5; and
e.currentTarget.frame_mc.alpha = 1; everything works.Anyone have issues with TweenLite like this?
- Pupsipu0
alpha works but tint doesn't? Try out alpha in TweenLite.
It unlikely to be a problem with TweenLite because it has been tested. Maybe you're trying to tint something that you're not supposed to be tinting. Check the tweenLite documentation.
- CyBrain0
You are correct. I was tweening tint, starting my line with
TweenLite.to(...
When I changed it to
TweenMax.to(...
everything worked.At first I called myself a dumbass dolt, but I checked the
TweenLite/TweenMax plugin explorer demo on this page.
http://blog.greensock.com/tweenm…
and it generates code beginning with TweenLite.
- Pupsipu0
yea but it generates the activate plugin code for TweenLite too, which would make tint work.
- CyBrain0
Yeah, TweenPlugin.activate([TintPlugin... allowed me to use TweenLite instead of TweenMax, so I am a dumbass dolt afterall.