"ENTER_FRAME" Vs "MOUSE_OVER"
I am encountering an interesting error that someone hopefully can shed some light on.
I have an object that i want to remove from a Sprite once the y value reaches 0.
i made a Sprite and put one thing in it.
PHP Code:
var container:Sprite = new Sprite(); addChild(container); var lB:Barrier = new Barrier(); container.addChild(lB);
I also added a mouse_over listener and a enter_frame listener.
now i have a different function that goes with the two listeners. in both of them i have a line for removing the lB clip.
PHP Code:
container.removeChild(DisplayObject(evt.target));
the line works just fine in the mouse_over function. when the enter_frame kicks in tho the clip gets removed also but then i get an error "The supplied DisplayObject must be a child of the caller" and the FPS go to about 1 lol
if anyone has any idea let me know .....tnx all
KirupaForum > Flash > ActionScript 3.0
Posted on: 09-04-2008, 03:15 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
MOUSE_OVER...really?
I've added a MOUSE_OVER event listener to a MC...works...kinda.
PHP Code:
targetMC.addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);
function mouseOverHandler (event:MouseEvent):void {
trace (event.target.name);
};
The trace return the name of the targetMC, but the odd thing is that it also returns the name of all the MCs inside the targetMC when the mouse goes over them!?! Can someone explain this one to me?
Is it possible to ignore the MCs inside targetMC?
Bug With MOUSE_OVER?
Ok so if you go to my work in progress at www.edg3creative.com/speaker.html and click stop , then mouse over the song title you will see my problem , on the very edges of the text box i used the popup still shows...below is how i coded...
ActionScript Code:
songBox.addEventListener(MouseEvent.MOUSE_OVER, showPop);
songBox.addEventListener(MouseEvent.MOUSE_OUT, hidePop);
songBox.addEventListener(MouseEvent.CLICK, getTunes);
function showPop(event:MouseEvent):void {
if (songBox.song_txt.text == "Audio Stopped") {
} else {
var songPop_alphain:Tween = new Tween(songPop, "alpha", Regular.easeInOut, 0, .65, .2, true);
}
}
function hidePop(event:MouseEvent):void {
var songPop_alphaout:Tween = new Tween(songPop, "alpha", Regular.easeInOut, .65, 0, .2, true);
}
is there any way to do this without that bug? Help very much appreciated! - Dale
Using An Already Loaded In XML On MOUSE_OVER
i thought this would be one of those simple things but it turns out it isnt.
i have an xml file that is loaded in and parsed, when i click a button it displays the xml code, but i am trying to get it so that when you MOUSE_OVER the same button, an element from the xml is displayed.
below is my code, as you can see at the minute i am just loading it in as a string, this was just so that i could get it working again.
PHP Code:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
import flash.text.*;
//var a:Array = [arrow1, arrow2]; // array holding the arrows
var building:Number = 1; //var _color:ColorTransform = new ColorTransform();
infobox.MainTween.myText.condenseWhite = true;
mapContainer.insideMap.library.addEventListener(MouseEvent.CLICK, beginXML);
function beginXML(event:MouseEvent):void {
xmlLoader.load(new URLRequest("campusxml.xml"));
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
}
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseBooks(xmlData);
mapContainer.insideMap.library.removeEventListener(MouseEvent.CLICK, beginXML);
}
function ParseBooks(campusBuildings:XML):void {
infobox.gotoAndPlay(2);
var Building:XMLList = campusBuildings.building.(@campusbuilding == "The Library");
infobox.MainTween.myText.htmlText = Building;
}
mapContainer.insideMap.library.addEventListener(MouseEvent.MOUSE_OVER, showBuilding);
function showBuilding(event:MouseEvent):void
{
var myText:String = "The Library";
mapContainer.buildingInstance.text = myText;
}
what would be the next best step, if i can just get it to trace any of the xml on the MOUSE_OVER then i will know what is going on but i can;t get it to do that?
Thanks
Dan
MOUSE_OVER Not Sensitive Enough?
Hi,
I'm trying to do a video playback control, like the normal ones, when you
mouseover the video, the control will appear. so I did this:
Code:
float.addEventListener(MouseEvent.MOUSE_OVER, getControl);
float.addEventListener(MouseEvent.MOUSE_OUT, removeControl);
private function getControl(e:MouseEvent):void {
if(mouseX > float.x + 20 && mouseX < float.x + 500 && mouseY > float.y + 20 && mouseY < float.y + 290) {
Tweener.addTween(bar_mc, {alpha:1, time:1});
}
}
private function removeControl(e:MouseEvent):void {
Tweener.addTween(bar_mc, {alpha:0, time:1});
}
I checked the code many times, but if I mouseover from the top of the
video, the control doesn't always appear, seems like if I move the mouse
faster, then it would appear. However, if I mouseover from the bottom, it
always appear... I find this really weird, does anyone know how to solve this?
Another thing is that although I set the eventlistener to detect mouseover to
a certain area, and the controlbar would appear, however, if my mouse is
over the controlbar, the controlbar would disappear. Why is that?
Here's the complete code
Code:
package {
import flash.display.*;
import flash.system.Capabilities;
import flash.events.Event;
import flash.net.*;
import flash.media.Video;
import flash.events.MouseEvent;
import caurina.transitions.*;
public class main extends MovieClip {
var trailer:Video = new Video(480,270);
public function main():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
addEventListener(Event.ENTER_FRAME, enterframe)
resizeHandler(null);
rect.alpha = .8;
var conn:NetConnection = new NetConnection();
conn.connect(null);
var stream:NetStream = new NetStream(conn);
//float.addChild(trailer);
trailer.attachNetStream(stream);
//stream.play("trailer.flv");
var metaListener:Object = new Object();
metaListener.onMetaData = theMeta;
stream.client = metaListener;
trailer.x = 20;
trailer.y = 20;
bar_mc.alpha = 0;
float.addEventListener(MouseEvent.MOUSE_OVER, getControl);
float.addEventListener(MouseEvent.MOUSE_OUT, removeControl);
bar_mc.play_mc.buttonMode = true;
bar_mc.stop_mc.buttonMode = true;
}
private function resizeHandler (e:Event):void {
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
rect.width = sw;
rect.height = sh;
}
private function enterframe(e:Event):void {
float.x = stage.stageWidth/2 - float.width/2;
float.y = stage.stageHeight/2 - float.height/2;
bar_mc.x = float.x + 20;
bar_mc.y = float.y + trailer.height - 10;
}
private function theMeta(data:Object):void {
var totalLength = data.duration;
}
private function getControl(e:MouseEvent):void {
if(mouseX > float.x + 20 && mouseX < float.x + 500 && mouseY > float.y + 20 && mouseY < float.y + 290) {
Tweener.addTween(bar_mc, {alpha:1, time:1});
//trace("in")
}
}
private function removeControl(e:MouseEvent):void {
Tweener.addTween(bar_mc, {alpha:0, time:1});
//trace("out")
}
}
}
Thanks in advance!
Christine
Looping Mouse_Over?
Howdy,
I want to do a glow effect when you MOUSE_OVER a button, and while the mouse remains over the button, have the glow pluse. I have the glow working on enterframe, using the code from http://board.flashkit.com/board/show...ight=glow+loop
PHP Code:
import flash.filters.GlowFilter;
var dir:Number = 1;
var myStrength:uint = 1.5;
my_mc.myStrength = myStrength;
my_mc.filters = [new GlowFilter(0xFF0000,1,25,25,myStrength)];
my_mc.addEventListener (Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler (event:Event):void
{
my_mc.myStrength += dir;
if (my_mc.myStrength >= 2.5)
{
dir -= 1;
}
else if (my_mc.myStrength <= 1.5)
{
dir += 1;
}
var filter_array:Array = my_mc.filters;
filter_array[0].strength = my_mc.myStrength;
my_mc.filters = filter_array;
}
But it only works once when I put it on the MOUSE_OVER.
I'm new to AS3, so please bear with me.
Thanks in advance.
-P
MOUSE_OVER Under MovieClip
Ok so I have two movieClips
one is semi-transparent the one under it has a MOUSE_OVER event,
I want the mouse to react to the Lower MovieClip (see through the top MovieClip)
how should I go about that ?
Mike
How Do I Know When MOUSE_OUT Here = MOUSE_OVER There?
This should be easy, but I'm stumped: picture a drop-down menu, where the mouse is over a top rectangle, and a rectangle below it is visible (playhead is at a certain frame, and lower rectangle's alpha = 1). When a listener detects that the top rectangle had a MOUSE_OUT event, some code now executes (playhead moves and lower rectangle's alpha is now going back to 0), but this code should execute only if there was no concurrent MOUSE_OVER event on the lower rectangle.
There is already an invisible button behind everything that I use for mouseout events, but it doesn't help when the mouse is moving downards into visible rectangles that need to remain visible.
I thought there is now a "type" property that should indicate mouse status related to an object, but didn't have any luck. Or maybe I should be using techniques of child and parent MCs, but I don't have the hang of those in AS 3.
Suggestions?
Mouse_Over Within HTMLText
Has anyone ever tried to run an actionscript function when hovering over the <a>Anchor tag of HTMLtext?
While one can add a "Hover" effect with CSS, i wish to run a function when an EVENT LINK is hovered over.
Is this possible, or inpossible?
var htmlText1:String = "<a href='event:hoverOverMe'>Hover Here Please</a>";
this.textArea1.htmlText = htmlText1;
this.textArea1.addEventListener("MOUSE_OVER", overHandler)
public function overHandler(event:MouseEvent)
{
//Get mouseover information
//Possible get information from the anchor tag under the mouse?
}
Any help to point me in the right direction is appreciated.
-CoderAmungus
Using MOUSE_OVER Syntax
I'm having troulbe with the MOUSE_OVER command. I want to get the name of whichever shape the mouse is over, but can't find an example in my manual on how to do that. All I have is:
this.stage.addEventListener(MouseEven,MOUSE_OVER, );
and don't know where to go from there. Any ideas?
MouseEvent.MOUSE_OVER HELP
Hey this is my first post in a forum ever, and I don't know if I will post this question right, but I am working on a simple menu system in AS3 that consists of some movie clips to move when moused over.
But when I run my code I get an error that I don't understand
1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
This is my code that I am using, could anyone enlighten me as to what this error means?
ActionScript Code:
package { import flash.display.*; import flash.events.*; public class blueBox extends MovieClip{ public function blueBox () { blueBox.addEventListener(MouseEvent.MOUSE_OVER, menuMove); } public function menuMove (event:MouseEvent):void { this.x++; } }}
- Confused????
- boomStick
OnRollOver Vs. MOUSE_Over
i'm totally new to AS 3.0 and eager to learn as much as possible.
question:
so what if any difference is there between onRollOver and MOUSE_Over?
also,
is there any harm in learning to use tweener to do my tweens instead of cs3's native tween class?
for example, what if i use tweener but someone else who works on my code doesn't know how, would it be best, while i'm learning to use 3.0 to stick with tweening using the native Tween class until i master it, and then move on to Tweener or a similar tween engine???
thanks!
MOUSE_OVER And Sound..
Ok, I have a movie clip that is coded as a button. When i MOUSE_OVER it I would like it to play a sound from my library (it is also a preset in flash as "Impact Wood Drop 04.mp3" )
Thanks for your help in advance!
Different MOUSE_OVER, MOUSE_OUT Odd Behaviour
sorry for another post but i've been trying to crack this one for a few hours now. on the stage within a mc is a button and when you click it and move out of the button i get the following error:
TypeError: Error #1010: A term is undefined and has no properties.
at Map_fla::MainTimeline/mouseOutHandler()
TypeError: Error #1010: A term is undefined and has no properties.
at Map_fla::MainTimeline/mouseMoveHandler()
TypeError: Error #1010: A term is undefined and has no properties.
with the MoveHandler repeating everytime the mouse is moved.
but the odd thing is.. i have buttons which allow the user to zoomIn which changes the cursor and then another button which cancels the button.. if i use these functions then i dont get the error.
Below is the entire code, i would load the fla but it is 22mb lol
PHP Code:
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import fl.motion.MatrixTransformer;
var tweenDirection:String;
var internalPoint:Point;
var externalPoint:Point;
var tw:Tween;
// instantiate your two arrow classes
var arrow1:Sprite = new zoomInCursor();
var arrow2:Sprite = new zoomOutCursor();
var a:Array = [arrow1, arrow2]; // array holding the arrows
var b:Array = [btn1, btn2]; // array holding the buttons
var i:Number; // associated number
var q:Number = 1;
btn3.addEventListener(MouseEvent.CLICK, defaultCursor);
// add the event listener to each button from the "b" array
for each (var element:Button in b)
{
this.addEventListener(MouseEvent.CLICK, buttonClick);
}
function defaultCursor(event:MouseEvent):void
{
if (a[i] != null)
{
// remove the current cursor from the stage
removeChild(getChildByName("mc" + i));
i = 3;
}
}// end of defaultCursor
// on menu button click
function buttonClick(event:MouseEvent):void
{
// check if the first button has been clicked
if (event.target.name == b[0].name)
{
if (a[i] != null)
{
// if the blue cursor already exists then
// remove it from the stage
removeChild(getChildByName("mc" + i));
}
i = 0;
mapContainer.insideMap.removeEventListener(MouseEvent.CLICK, zoomOut);
mapContainer.insideMap.addEventListener(MouseEvent.CLICK, zoomIn);
}
// if not, then the second button has been clicked
else if (event.target.name == b[1].name)
{
if (a[i] != null)
{
// if the red cursor already exists then
// remove it from the stage
removeChild(getChildByName("mc" + i));
}
i = 1;
mapContainer.insideMap.removeEventListener(MouseEvent.CLICK, zoomIn);
mapContainer.insideMap.addEventListener(MouseEvent.CLICK, zoomOut);
}
// call the function that replaces your default cursor
mapContainer.insideMap.addEventListener(Event.ENTER_FRAME, onEnterZoom);
mapContainer.insideMap.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
mapContainer.insideMap.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
}
function onEnterZoom(event:Event):void
{
if (i == 0 || i == 1)
{
addChild(a[i]);
a[i].name = "mc" + i;
a[i].x = mouseX;
a[i].y = mouseY;
a[i].mouseEnabled = false;
}
if (i == 3)
{
mapContainer.insideMap.removeEventListener(MouseEvent.CLICK, zoomIn);
mapContainer.insideMap.removeEventListener(MouseEvent.CLICK, zoomOut);
mapContainer.insideMap.removeEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
mapContainer.insideMap.removeEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
// remove the enter frame listener from the stage
stage.removeEventListener(Event.ENTER_FRAME, onEnter);
// show the default cursor
Mouse.show();
}
}
function mouseOverHandler(event:MouseEvent):void {
// trace("mouseOverHandler");
Mouse.hide();
mapContainer.insideMap.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
function mouseOutHandler(event:MouseEvent):void {
// trace("mouseOutHandler");
Mouse.show();
mapContainer.insideMap.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
a[i].visible = false;
}
function mouseMoveHandler(event:MouseEvent):void {
event.updateAfterEvent();
a[i].visible = true;
}
function zoomIn($e:MouseEvent):void
{
if(q==4)
{
mapContainer.insideMap.removeEventListener(MouseEvent.CLICK, zoomIn);
}
internalPoint = new Point(mapContainer.insideMap.mouseX, mapContainer.insideMap.mouseY);
externalPoint = new Point(mapContainer.insideMap.mouseX, mapContainer.insideMap.mouseY);
if (q < 4)
{
q += 1;
}
trace (q);
tw = new Tween(null, "", Strong.easeOut, mapContainer.insideMap.scaleX, q, 1, true);
tw.addEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
}
function _syncScale($e:TweenEvent):void{
mapContainer.insideMap.scaleX = mapContainer.insideMap.scaleY = tw.position;
var matrix:Matrix = mapContainer.insideMap.transform.matrix;
MatrixTransformer.matchInternalPointWithExternal(matrix, internalPoint, externalPoint);
mapContainer.insideMap.transform.matrix = matrix;
}
function _cleanTween($e:TweenEvent):void
{
tw.removeEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.removeEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
tw = null;
}
function zoomOut($e:MouseEvent):void
{
if(localToGlobal == null)
{
}
externalPoint = stage.localToGlobal(internalPoint);
internalPoint = stage.globalToLocal(externalPoint);
if (q > 1)
{
q -= 1;
}
if (q==1)
{
mapContainer.insideMap.removeEventListener(MouseEvent.CLICK, zoomOut);
}
trace (q);
tw = new Tween(null, "", Strong.easeOut, mapContainer.insideMap.scaleX, q, 1, true);
tw.addEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
}
thanks
Dan
MOUSE_OVER And MOUSE_OUT.. Help Needed
Hello there
I need a little help with the MOUSE_OVER and MOUSE_OUT commands.
Basically ive got a little part of a site ive made in flash where i want to roll over a section and out pops a side bar, i then want it to disappear again when the mouse leaves the side bar...
Ive set up within the 1 movie clip 2 sections (the opening of the bar and the closing of the bar) with stop(); tags at the end of each sequence to stop them running into eachother.
So for example its setup like this:
PHP Code:
this.buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_OVER,function():void {
gotoAndPlay("open")
}
);
this.addEventListener(MouseEvent.MOUSE_OUT,function():void {
gotoAndPlay("close")
}
);
The problem is that obviously everytime the mouse goes over the section (this.) it then resets itself back to the beggining of the "open" sequence.
I need it to open when the mouse goes over it and stay open until the mouse leaves the movie clip again.
Please help!!
Dynamic MOUSE_OVER Animation
Hey there- An AS3 animation question.
I have successfully created a simple MOUSE_OVER animation that rotates a graphic when it's parent movieclip is moused over, and pauses when the mouse is taken away. Now the tricky part. I would like the movieclip to know when the user has returned the mouse over the clip and rotate the graphic in the opposite direction, and loop that function back and forth. So if the user returned the mouse a third time, the animation would begin to rotate in the direction it initially started.
Here's the simple working animation thus far (which rotates the graphic cw):
Code:
container.addEventListener(MouseEvent.MOUSE_OVER, overLogo);
function overLogo(evt:MouseEvent){
container.flake_mc.addEventListener(Event.ENTER_FRAME, rotate);
container.addEventListener(MouseEvent.MOUSE_OUT, pauseRotate);
}
function rotate(event:Event):void {
container.flake_mc.rotation += 2;
}
function pauseRotate(event:Event):void {
stop();
container.flake_mc.removeEventListener(Event.ENTER_FRAME, rotate);
}
I'm assuming some type of conditional needs to be stated, but I'm just not sure what that would be. Any help is appreciated! Thanks!
Mouse_over Constant Feedback?
hi all.
my first post here.
i am a cs3 newby.
how the boogery do i do this? :-
i have a pic gallery and i want it to scroll constantly whilst the mouse is hovering over the left hand side. i can't seem to work out how to do this. the best i have got so far is using the mouse_move command but that only updates if the mouse is moved around within the defined space. all the others (mouse_over, etc) just fire once and that's it. i have played with while and if statements to no avail.
arggggh as the pirates say
thanks
adrian
MOUSE_OVER Inside A FOR LOOP?
Hi, I'm trying to create a MOUSE_OVER on all seperate added Children. What happens in my code is all newsBackground's recieve the listeneres and the last added newsBackground receives the functions. How can I tell the listeneres and functions on wich Child to act?
ActionScript Code:
for ( var i:uint=0 ; i<news.length(); i++) {
newsBackground = new MovieClip();
newsBackground.graphics.beginFill (0xFFFFFF);
newsBackground.graphics.drawRect (0, 0, 600, 90);
newsBackground.graphics.endFill();
newsBackground.y = i*(newsBackground.height + insidePadding)
newsBackground.alpha = .5;
newsBackground.addEventListener(MouseEvent.MOUSE_OVER, newsLinkOver);
newsBackground.addEventListener(MouseEvent.MOUSE_OUT, newsLinkOut);
addChild(newsBackground);
function newsLinkOver(e:MouseEvent):void {
newsBackground.alpha= 1;
}
function newsLinkOut(e:MouseEvent):void {
newsBackground.alpha= .5;
}
}
Help With Mouse_Over And _Out And AddChild
I'm using AS3 to bring a movie clip to the stage on a Mouse_OVER. I've used addChild. I'm then using a removeChild to take the image away on Mouse_OUT. It works great the first time but if I roll onto the mouse over area a second/third/etc time, the addChild doesn't work again. What am I missing?
Detect MOUSE_OVER On Movieclip
I'm assuming this is pretty straight forward but I'm not all that great with as3 yet.
I'd like to check if my mouse is currently over a movieclip.
Here's what I have so far:
Code:
box_mc.addEventListener(MouseEvent.MOUSE_OVER, checkBoundaries);
function checkBoundaries(evt:MouseEvent)
{
if(this.MOUSE_OVER != false){
trace("true");
}else {trace("false");}
};
This actually does give me a reading of true but not a reading of false if the mouse leaves the movieclip area.
Is there a better/simpler way to do this that works?
MOUSE_OVER Listener Problem
I have problem in MOUSE_MOVE listener
the logic is that mouse should hide while hitTestObject and the custom mouse should appear.Problem is mouse is appearing but it is blinking and even i tried
sinu_mc.addEventListener(MouseEvent.MOUSE_OUT,outL istener,true);
in the above code cur(custom mouse) isn't blinking but while moving out from hitTestObject custom mouse is appearing sometimes and it's n't so accurate and please help me to overcome this.
one more problem i faced
cur.x = mouseX;
cur.y = mouseY; inside the overlistener
but the position is difference from mouseX and mouseY and how to make synchronize that
movieclip with mouseX,Y properties.
-----------------------------------
SOURCE CODE
-----------------------------------
var cur:cursor = new cursor ();//movieclip with linkage id cursor
sinu_mc.addEventListener(MouseEvent.MOUSE_MOVE,overListener);
sinu_mc.addEventListener(MouseEvent.MOUSE_OUT,outL istener);
function overListener(m:MouseEvent){
if(sinu_mc.hitTestPoint(mouseX,mouseY,true)){
Mouse.hide();
sinu_mc.addChild(cur);
cur.startDrag(true);
cur.scaleX = cur.scaleY = .5;
cur.x = mouseX
cur.y = mouseY;
}
}
function outListener(m:MouseEvent){
Mouse.show();
sinu_mc.removeChild(cur);
}
Problems With MOUSE_OVER And MOUSE_OUT
I'm making a navigation menu for my website and I'm having a bit of trouble getting the animations to in the manner I want them to.
What I want:
A multi-tiered menu where a roll over of the mouse will reveal the next tier of the menu. For example, when you hover over the menu itself, it'll reveal "photos", "words", and "about" submenus. When you hover any of the second level buttons, it reveals another option.
What I have:
So far I've been able to get each menu to execute it's animation when hovered over. The animation is a simple motion tween going from a black tint to a white one. When the mouse leaves the button, it fades back to black. The problem has been keeping the animation in it's white state. If I move the mouse away too violently or quickly or at some akward angle, the animation will stay white (rather than fading back to black) so that the next time I hover over it, it becomes black.
I think it may be how I'm playing the movieclip. Perhaps one of you gurus can take a look at my ActionScript (AS3.0) and help me figure out what's going on. I'm a newbie with flash, so please excuse my limited knowledge of the program. Thanks!
/*LEVEL ONE*/
nav.addEventListener(MouseEvent.MOUSE_OVER, buttonNavOver);
function buttonNavOver(event:MouseEvent):void {
photos.gotoAndStop(5);
words.gotoAndStop(5);
info.play();
trace("I'm clicked!");
}
nav.addEventListener(MouseEvent.MOUSE_OUT, buttonNavOut);
function buttonNavOut(event:MouseEvent):void {
photos.gotoAndStop(5);
words.gotoAndPlay(5);
info.gotoAndPlay(5);
trace("I'm out!");
}
/*LEVEL TWO*/
BTphotos.addEventListener(MouseEvent.MOUSE_OVER, buttonPhotosOver);
function buttonPhotosOver(event:MouseEvent):void {
photojournalism.play();
}
BTphotos.addEventListener(MouseEvent.MOUSE_OUT, buttonPhotosOut);
function buttonPhotosOut(event:MouseEvent):void {
photojournalism.gotoAndPlay(5);
}
BTwords.addEventListener(MouseEvent.MOUSE_OVER, buttonWordsOver);
function buttonWordsOver(event:MouseEvent):void {
blog.play();
}
BTwords.addEventListener(MouseEvent.MOUSE_OUT, buttonWordsOut);
function buttonWordsOut(event:MouseEvent):void {
blog.gotoAndPlay(5);
}
BTinfo.addEventListener(MouseEvent.MOUSE_OVER, buttonInfoOver);
function buttonInfoOver(event:MouseEvent):void {
resume.play();
}
BTinfo.addEventListener(MouseEvent.MOUSE_OUT, buttonInfoOut);
function buttonInfoOut(event:MouseEvent):void {
resume.gotoAndPlay(5);
}
stop();
Mouse Pointer On MOUSE_OVER
Hey everybody, I am trying to get the mouse pointer to change to the "finger pointer" when you rollover this circle that is drawn by the actionscript.. any ideas? I couldn't get buttonmode to work and I don't want to use a custom pointer.
Code:
var circle:Shape = new Shape();
circle.graphics.beginFill(0x000000, 1);
circle.graphics.drawCircle(15, 15, 30);
circle.addEventListener(MouseEvent.CLICK, clicked);
circle.addEventListener(MouseEvent.MOUSE_OVER, rollover);
addChild(circle);
private function rollover(event:MouseEvent)
{
// make mouse pointer change to "finger pointer" state
}
thanks in advance!
Really Frustrating MOUSE_OVER, MOUSE_OUT Behavior
This is driving me crazy. I'm trying to create a custom drag cursor when the mouse is over a dragable object. Here is an excerpt of the code:
PHP Code:
this.loader.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
this.loader.addEventListener(MouseEvent.ROLL_OUT, mouseOut);
public function mouseMove(e:MouseEvent) {
dragCursor.alpha = 1;
Mouse.hide();
dragCursor.x = stage.mouseX;
dragCursor.y = stage.mouseY;
}
public function mouseOut (e:MouseEvent) {
trace (e.eventPhase + ': mouse out called');
dragCursor.alpha = 0;
Mouse.show();
}
The frustrating part of this is that whenever I'm over any object with MOUSE_OUT and/or MOUSE_OVER funcs defined, the out and over funcs seemed to be called randomly, when I move the mouse over the object (in this case a simple jpg). That is to say that the out and over funcs are called randomly, without ever rolling out of the area of the image. Why would this be? I've read the documentation for bubbling etc, and can find no reason for this behavior. I've tried for 5 hours all kinds of tests, but nothing works... Someone PLEASE HELP!
Menu Mouse_out/mouse_over Issue
I have constructed a menu.
It consists of a background and some links (movieclips).
When the mouse hovers over a link a selection is dragged to be placed underneath that link. And when the mouse leaves the menuarea the selection is supposed to return to its original position.
I am using a tweeneffect for the animation of the selection.
My problem is that when moving the mouse over a link it registers the mouse_over event for that movieclip (this is correct), but it also registers a mouse_out event for the background since the links are placed on top of the background. This causes a glitch in the animation of the selection.
When i move the mouse over a link I only want it to be registered as a mouse_over event for that link, not a mouse_out event for the menu-background
What is the best work around to avoid this?
Im pasting some of the code i have at the moment to clarify my problem.
code:
menu_bg_mc.addEventListener(MouseEvent.MOUSE_OUT,r eturnSelection);
function returnSelection(evt:MouseEvent):void {
var cFrame = MovieClip(root).currentFrame;
if(cFrame == 1) {
new Tween(selection_mc,"x",Strong.easeOut,selection_mc .x,home_mc.x,1,true);
}
}
home_mc.addEventListener(MouseEvent.ROLL_OVER, hover);
home_mc.addEventListener(MouseEvent.CLICK, goToFrame);
function hover(e:MouseEvent):void {
new Tween(selection_mc,"x",Strong.easeOut,selection_mc .x,e.currentTarget.x,0.5,true);
}
Color Tabs On MouseEvent.MOUSE_OVER
So I have a create tabs function. I'm having a lot of trouble changing the color of tabStage.tabStage_mc in tabMouseOverHandler. Can I reference the movieclip tabStage_mc in the appropriate array index? I hope this makes sense.
ActionScript Code:
function createTabs() {
tabsContainer = new MovieClip();
tabsContainer.rotation = tabRotation;
addChild(tabsContainer);
var i:uint;
for (i = 0; i < tabNumber; i++) {
tabContainer = new MovieClip();
tabsContainer.addChild(tabContainer);
tabStage = new Tab();
tabStage.buttonMode = true;
tabStage.addEventListener(MouseEvent.CLICK, tabClickHandler);
tabStage.addEventListener(MouseEvent.MOUSE_OVER, tabMouseOverHandler);
tabBorderColor.color = this["tab"+(i+1)+"BorderColor"];
tabStage.tabBorder_mc.transform.colorTransform = tabBorderColor;
tabStageColor.color = this["tab"+(i+1)+"StageColor"];
tabStage.tabStage_mc.transform.colorTransform = tabStageColor;
tabStage.filters = tabFiltersArray;
tabContainer.addChild(tabStage);
tabText = new TextField();
tabText.mouseEnabled = false;
tabText.defaultTextFormat = tabTextFormat;
tabText.embedFonts = true;
tabText.text = this["tab"+(i+1)+"Txt"];
tabText.selectable = false;
tabText.autoSize = "center";
if (tabText.textWidth+tabTextPadding <= 110) {
tabStage.width = 110;
} else {
tabStage.width = tabText.textWidth+tabTextPadding;
}
tabText.x = (tabStage.width-tabText.width)/2;
tabContainer.addChild(tabText);
tabArray.push(tabContainer);
}
var j:uint;
for (j = tabNumber; j > 0; --j) {
if (j == tabNumber) {
tabArray[j-1].x = tabStartX;
tabArray[j-1].y = tabStartY;
} else {
tabArray[j-1].x = tabArray[j].x-tabArray[j-1].width+tabOverLay;
tabArray[j-1].y = tabStartY;
}
}
}
function tabClickHandler(e:MouseEvent):void {
//e.target.scaleX = e.target.scaleY = 1.5;
}
function tabMouseOverHandler(e:MouseEvent):void {
//e.target
}
Mouse_over= Forward Mouse_out= Backwards. How The...?
Hi there people, I'm very new to actionscripting, so I've decided to start out with AS3 instead of the seemingly more popular AS2.
This is what I'm trying to achieve:
I have a movie clip (called starboy, a star that shape tweens into a boy).
Could be just a button, doesn't really matter.
This movie clip has its tween across 20 frames.
I want it to behave like this;
I hover the mouse OVER the mc, it starts playing forward through the tween. When I retract my mouse away from the mc, it should play backwards. In other words, not just jump to a certain frame or anything.
Now, I've found tons of example fla's and tutorials explaining how to do this in AS2, and they all work nicely. I've found none for AS3 though.
With my non-existans coding experience I embarked on this and concocted the following on the first frame of this movie clip (in a separate layer called actions of course):
this.stop();
var rewind:Boolean = false;
this.addEventListener(MouseEvent.MOUSE_OVER, forward);
function forward(event:MouseEvent):void
{ rewind = false;
this.play();
}
----------
And, on the second frame, this is my code:
------------
this.addEventListener(Event.ENTER_FRAME, checker);
function checker(event:MovieClip):void
{
if (rewind = true)
{
this.stop();
this.prevFrame();
}
}
this.addEventListener(MouseEvent.MOUSE_OUT, backward);
function backward(event:MouseEvent):void
{ (rewind = true)
this.prevFrame();
}
------
Now, the result of this mess is the mc sitting quietly on stage, until I move the mouse over it and the output giving me an error message:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@302cb01 to flash.display.MovieClip.
And it puts out one of those like every 0.4 seconds until I stop the playback manually.
I realized I should probably have the code from frame 2 copied to all the other frames, but that just gave me a duplicate error when running.
So down to the question:
How to fix this?
Or more interestingly, how would YOU code this to be as small, neat and efficient as possible?
And on a sidenote or two:
I put this.stop(); in the start to not have it play until I want it to. If just putting stop();, does flash assume I mean "this"?
And what is :void? I just put it there since I saw many examples of that and assumed it has to be there.
Please don't be discouraged about my totally ignorant appearance , I do learn quickly (I've fiddled with flash for 1.5 days now) so any help will go a LONG way and will not be in vain.
Menu Mouse_out/mouse_over Issue
I have constructed a menu.
It consists of a background and some links (movieclips).
When the mouse hovers over a link a selection is dragged to be placed underneath that link. And when the mouse leaves the menuarea the selection is supposed to return to its original position.
I am using a tweeneffect for the animation of the selection.
My problem is that when moving the mouse over a link it registers the mouse_over event for that movieclip (this is correct), but it also registers a mouse_out event for the background since the links are placed on top of the background. This causes a glitch in the animation of the selection.
When i move the mouse over a link I only want it to be registered as a mouse_over event for that link, not a mouse_out event for the menu-background
What is the best work around to avoid this?
Im pasting some of the code i have at the moment to clarify my problem.
ActionScript Code:
menu_bg_mc.addEventListener(MouseEvent.MOUSE_OUT,returnSelection);
function returnSelection(evt:MouseEvent):void {
var cFrame = MovieClip(root).currentFrame;
if(cFrame == 1) {
new Tween(selection_mc,"x",Strong.easeOut,selection_mc.x,home_mc.x,1,true);
}
}
home_mc.addEventListener(MouseEvent.ROLL_OVER, hover);
home_mc.addEventListener(MouseEvent.CLICK, goToFrame);
function hover(e:MouseEvent):void {
new Tween(selection_mc,"x",Strong.easeOut,selection_mc.x,e.currentTarget.x,0.5,true);
}
Another Dreadful MOUSE_OVER/OUT Button Question
Might anyone have any suggestions as to how to get this nav button working?
I need it to pop out on a MOUSE_OVER event — as it does — but then stay open until the mouse moves off of it while the buttons inside remain accessible, as anyone who cares to take a look will see doesn't work.
Many thanks. And special thanks to those who've helped with the various aspects of this project already.
http://www.bricehall.com/misc/troubleShoot_1.fla
Movieclips Overlaping Problem With MOUSE_OVER
Hi, I have a movieclip that shall work like a button, however that is a later problem, atm I just want it to animate when I place the mouse over, and then when I move the mouse away I want another animation.
So what I have is
Code:
var over = 0;
test_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
if(over == 0){
test_mc.gotoAndPlay("over");
over = 1;
}
}
);
test_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
if(over == 1){
test_mc.gotoAndPlay("out");
over = 0;
}
}
);
There might be some fault with bracets since Ive been trying out diffrent things from time to time, but I hope you understand the principle here, I basicly just say that when the mouse is over the movieclip, play one part of it, and when it goes out play another part.
Now the problem is that the movieclip that it plays goes over the button, and thus the MOUSE_OVER will stop since there is a new movieclip over, so the animation stops when it hits the curser, and since it is then out (since its not over) it will start the out animation, but since it is over when the first movie goes away it starts the over movie again
So what it does is that it loops the over animation all the time.
Is there any way to get the MOUSE_OVER to work on the cordinatates of the object or in some other way make this works. It's hard to explane, please ask if Im unclear.
I tried to move the gotoAndPlay out and have it in a function so that it wont stop when its not over anymore and that works, ok, but it will still register alot of over's and out's.
I would like to have some sort of focus, so that when it listens to MOUSE_OVER, it only cares about x,y positions, not if there is a new movieclip that happens to overlap the old one.
Passing Params Thru MOUSE_OVER Event?
I have a function that needs to be called when the mouse is moved over a button that has been attached to the stage. The function is called scrollZone. However, I need to pass scrollZone some parameters.... but how? Whatever I do seems to result in a compile error.
ActionScript Code:
btnDown.addEventListener(Event.MOUSE_OVER, scrollZone);
I want to be able to do something like this:
ActionScript Code:
btnDown.addEventListener(Event.MOUSE_OVER, scrollZone(param1,param2,param3));
Can someone give me the correct syntax?
Thanks!
E:MouseEvent):void { E.mouse_over = Boolean ?
I was doing a simple button with mouse on and over actions...
objection.addEventListener(MouseEvent.MOUSE_OVER,o bj);
objection.addEventListener(MouseEvent.MOUSE_OUT,ob j);
And then I got this idea, why not to use the sane function for both events? Then when inside the function, I could ask if the event was MOUSE_OVER or OUT?
Something like this:
function obj(e:MouseEvent):void {
Do_something()
if(e.mouse_on==true){
Do_another_thing
} else {
Restore_Cuba_democracy()
}
}
Theres someting like this availble in as 3.0? I googled a little and found nothing. Maybe I used the wrong words in search...
By the way, the Cuba Democracy is a joke. I dont know how Cuba is and I dont care too. I like because the episode where SouthPark guys done that.
}
Nesting CLICK Inside MOUSE_OVER?
HI All...
following scenario:
I add an mc as a container stick another mc inside for the navigation bar
and place a "button" mc inside that.
so:
Code:
root1 [object WB_X]
NaviBox [object MovieClip]
Navi [object Helm_mc]
[object Shape]
Home [object Btn_1]
[object Shape]
NaviBox: listens for MOUSE_OVER, on which Navibox and all content moves.
Navi: is just pretty but has no real purpose in this...
Home: is the "button" listening for MOUSE_UP
all dandy... NOT!?
NaviBox responds to MOUSE_OVER fine and does its thing, BUT
as soon as you MOUSE_OVER the Home "Button" it triggers the tween to reverse
NaviBox.
I've tried all different nesting orders I could think of
and tried all parameters for the addEventListener and lots of other nasty things
that are too private to elaborate in public,
I am not getting ANYWHERE and frankly... my brain hurts.
please can some one put me out of my misery?
Code here:
/////////////////////////////////////////////////////////////////////
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import fl.transitions.*;
import fl.transitions.easing.*;
public class WB_X extends MovieClip {
public function WB_X() {
var NavCon:MovieClip = new MovieClip();
NavCon.name = "NaviBox"
addChildAt(NavCon, 0);
var Helm:MovieClip = new Helm_mc;
Helm.name = "Navi";
NavCon.addChildAt(Helm, 0);
Helm.x = 20;
Helm.y = 20;
var STGE:MovieClip = new BG_mc;
STGE.name = "BG_cont";
addChildAt(STGE, 0);
var BtnOne:MovieClip = new Btn_1;
BtnOne.name = "Home"
Helm.addChildAt(BtnOne,1);
BtnOne.x = -150;
BtnOne.y = 10;
NavCon.addEventListener(MouseEvent.MOUSE_OVER, helmover, false, 0, true);
NavCon.addEventListener(MouseEvent.MOUSE_OUT, helmout, false, 0, true);
BtnOne.addEventListener(MouseEvent.CLICK, CLICKED, false, 0, true);
var starton:Number = Helm.x;
var stopon:Number = 690;
var stopon2:Number = 20;
var dur:Number = 1;
//var helmer:Tween = new Tween(Helm, "x", Bounce.easeOut, starton, stopon, dur, true);
function helmover() :void {
NavCon.removeEventListener(MouseEvent.MOUSE_OVER, helmover);
new Tween(NavCon, "x", Bounce.easeOut, starton, stopon, dur, true);
starton = 690;
}
function helmout() :void {
NavCon.addEventListener(MouseEvent.MOUSE_OVER, helmover);
new Tween(NavCon, "x", Bounce.easeOut, starton, stopon2, dur, true);
starton = 20;
}
function CLICKED() :void {
trace("I HAVE FINALY BEEN CLICKED!!");
}
//TRACES DISPLAY LIST AND SORTS RESULTS WITH INDENTS//VVVVVVVVVVVVVVVVVVVVVVVVV
function showChildren(dispObj:DisplayObject, indentLevel:Number):void {
for (var i:int = 0; i < dispObj.numChildren; i++) {
var obj:DisplayObject = dispObj.getChildAt(i);
if (obj is DisplayObjectContainer) {
trace(padIndent(indentLevel),obj.name, obj);
showChildren(obj, indentLevel + 1);
} else {
trace(padIndent(indentLevel) + obj);
}
}
}
showChildren(stage, 0);
function padIndent(indents:int):String {
var indent:String = "";
for (var i:Number = 0; i < indents; i++) {
indent += " ";
}
return indent;
}
////////////////////////////////////////////
}
}
}
Any input will be greatfully received.
Lexic13
Timeline Control Of An Embedded FLV Using MOUSE_OVER?
I have an .FLV file embedded into the timeline and I want to control the playback direction using the X position of the mouse pointer (with regard to the stage center); acheiving a similar effect to Lee's excellent carousel tutorials.
I'm guessing that adding an eventListener for MouseEvent.MOUSE_OVER and comparing the X position to the stage.width/2 is the way to go?
I am very new to flash and would greatly appreciate your help.
MOUSE_OVER And Nested Movie Clips Problem
Hi,
I have a situation where i create a parent movie clip and use addChild() method to add couple more movie clips (circle shapes from library) to it (with space between them naturally since child objects are circles). When i set onRollOver event for my main movie clip it gets triggered in fact when i roll over it's child objects(circles) and rolling over space between them will in fact trigger rollOut event which i don't want. I would like to use onRollOver on my whole main movie clip with its child circles so if anyone could help i would really appreciate it. Here is a sample code i am using:
Code:
var mainMC:MovieClip = new MovieClip();
var childMC:Array = new Array();
for (var i:uint=0; i <5; i++){
childMC[i] = new Circle(); //Circle is 'circle' shape attached from library
mainMC.addChild(childMC);
}
stage.addChild(mainMC);
mainMC.addEventListener(MouseEvent.ROLL_OVER, mainOver);
mainMC.addEventListener(MouseEvent.ROLL_OUT, mainOut);
...
thanks,
best regards
Event Handling And MOUSE.ROLL_OVER And MOUSE_OVER
hello everyone,
i have been learning AS3 for couple of weeks now and been getting with creating my website. however, i have gotten to the point where interactivity needs to be implemented.
basically what i want is this:
i want to have for example two buttons or sprites on the stage not nested and have RollOver and RollOut events triggered accordingly. However, when MouseDown on Stage and then RollOver on btn1 or btn2 I dont want any events triggered. RollOver should be triggered only when directly RollOver or when MouseUp from Stage or other object.
Bellow is the code i have been writing and it does what i want to some extent:
what this code below does is this:
when MouseDown on Stage listener for RollOver on btn1 is removed
when MouseUp directly on Stage listener for RollOver on btn1 is added
when MouseDown on Stage and MouseUp on btn1 RollOver on btn1 is called (exactly what i needed when i add tweens)
???? the question still remains now, what about if i have more then one button and when you MouseDown on Stage and MouseUp on respective button all RollOver events will be triggered.
Any ideas on how to implement this better, anyone?
What about using some custom events and dispatch them accordingly? I am still learning AS3 therefore i do not have enough overall knowledge about the best implementation and how to go about things.
Here is the code:
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_stage);
trace("Added MouseDown on Stage");
btn1.addEventListener(MouseEvent.ROLL_OVER, onRollOver_btn1);
trace("Added RollOver on btn1");
private function onRollOver_btn1(e:MouseEvent):void {
trace("RollOver btn1" + e.target + e.currentTarget + e.eventPhase);
btn1.removeEventListener(MouseEvent.ROLL_OVER, onRollOver_btn1);
trace("-removed RollOver btn1");
btn1.addEventListener(MouseEvent.ROLL_OUT, onRollOut_btn1);
trace("+added RollOut btn1");
trace("-removed MouseDown Stage" + e.target + e.currentTarget + e.eventPhase);
stage.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_stage);
trace("-removed MouseUp Stage" + e.target + e.currentTarget + e.eventPhase);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp_stage);
}
private function onRollOut_btn1(e:MouseEvent):void {
trace("RollOut btn1 " + e.target + e.currentTarget + e.eventPhase);
btn1.removeEventListener(MouseEvent.ROLL_OUT, onRollOut_btn1);
trace("-removed RollOut btn1");
btn1.addEventListener(MouseEvent.ROLL_OVER, onRollOver_btn1);
trace("+added RollOver btn1");
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_stage);
trace("+added MouseDown Stage");
}
private function onMouseDown_stage(e:MouseEvent):void {
if(e.target == e.currentTarget){
trace("MouseDown directly Stage" + e.target + e.currentTarget + e.eventPhase);
stage.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_stage);
trace("-removed MouseDown Stage");
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp_stage);
trace("+added MouseUp Stage");
btn1.removeEventListener(MouseEvent.ROLL_OVER, onRollOver_btn1);
trace("-removed RollOver btn1");
}
}
private function onMouseUp_stage(e:MouseEvent):void {
if(e.target == e.currentTarget){
trace("MouseUp direclty Stage" + e.target + e.currentTarget + e.eventPhase);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp_stage);
trace("-removed MouseUp Stage");
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_stage);
trace("+added MouseDown Stage");
btn1.addEventListener(MouseEvent.ROLL_OVER, onRollOver_btn1);
trace("+added RollOver btn1");
}else{
trace("MouseUp somewhere else but Stage" + e.target + e.currentTarget + e.eventPhase);
onRollOver_btn1(e);
}
}
cheers,
janis
MOUSE_OVER And Nested Movie Clips Problem
Hi,
I have a situation where i create a parent movie clip and use addChild() method to add couple more movie clips (circle shapes from library) to it (with space between them naturally since child objects are circles). When i set onRollOver event for my main movie clip it gets triggered in fact when i roll over it's child objects(circles) and rolling over space between them will in fact trigger rollOut event which i don't want. I would like to use onRollOver on my whole main movie clip with its child circles so if anyone could help i would really appreciate it. Here is a sample code i am using:
Code:
var mainMC:MovieClip = new MovieClip();
var childMC:Array = new Array();
for (var i:uint=0; i <5; i++){
childMC[i] = new Circle(); //Circle is 'circle' shape attached from library
mainMC.addChild(childMC);
}
stage.addChild(mainMC);
mainMC.addEventListener(MouseEvent.ROLL_OVER, mainOver);
mainMC.addEventListener(MouseEvent.ROLL_OUT, mainOut);
...
thanks,
best regards
Event Handling And MOUSE.ROLL_OVER And MOUSE_OVER
Hello everyone,
For quite some time I have been trying to figure out ways how make the proper interactivity for my sprites.
The sample scenario is this basically:
------One container sprite lets call it (CONT) on the Stage holding two seperate sprites (BTN1) and (BTN2)
------CONT, BTN1, and BTN2 sprites have MOUSE_OVER, MOUSE_OUT, MOUSE_DOWN, and MOUSE_UP event listeners
Now, I also tried this with ROLL_OVER and ROLL_OUT events since they do not bubble but I cant get the outcome what i am looking for.
What i am trying to achieve is this:
///////// When mouse_over BTN1, then mouse_down on BTN1 and do mouse_up outside BTN1 and CONT meaning mouse_up on Stage then what should happen is this: mouse_out on BTN1, mouse_out on CONT and that's it.
Also, when mouse_down on Stage and mouse_over CONT and then BTN1 or BTN2 nothing should happen but it does with the code that i have been writing.
Your help or suggestions would be appreciated.
I have tried to check on mouse_up events whether e.target == e.currentTarget and if so then I know that mouse_down comes from the same sprite that mouse_up is triggered. But if i have two sprites like in the example above with BTN1 and BTN2, and i check for e.target and e.currentTarget then if mouse_down on BTN1 and mouse_up on BTN2 i still get the event triggered because e.target and e.currentTarget is of object Sprite.
Any ideas???
Thanks,
Janis
ENTER_FRAME Handler
i got a btn_mc on stage, 10 frames length, the width shape tweens from 1 -> 50
this is my actionscript :
ActionScript Code:
btn_mc.buttonMode = true;
btn_mc.addEventListener(MouseEvent.ROLL_OVER, btn_rollOver);
function btn_rollOver(event:MouseEvent):void
{
event.currentTarget.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
function btn_rollOut(event:MouseEvent):void
{
event.currentTarget.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
event.currentTarget.addEventListener(Event.ENTER_FRAME, exitFrameHandler);
}
function enterFrameHandler(event:Event):void
{
event.currentTarget.nextFrame();
event.currentTarget.addEventListener(MouseEvent.ROLL_OUT, btn_rollOut);
}
function exitFrameHandler(event:Event):void
{
btn_mc.prevFrame();
if (event.currentTarget.currentFrame == 1)
{
event.currentTarget.removeEventListener(Event.ENTER_FRAME, exitFrameHandler);
}
}
nextFrame() and prevFrame() seem to work allright, but you can manage to pause the prevFrame() function if you rollOver it again quickly.
so from what i can tell what is happening :
btn_mc gets a ROLL_OVER event, if ROLL_OVER event occurs, btn_mc enterFrameHandler starts running, and keeps playing nextFrame(). Also an ROLL_OUT event is added at this time. So when we ROLL_OUT, exitFrameHandler starts prevFrame() until the currentFrame of the btn_mc == 1, it then removes the exitFrameHandler.
what happens now is that when your ROLL_OVER, ROLL_OUT and immediatly ROLL_OVER again, the nextFrame() should be running again, but this doesnt happen, it seems enterFrameHandler is not being started, prevFrame() pauses on a certain frame, even though it is listening...
anyone care to see what the potential problem is ?
Kind regards,
Juan
Why Can't I Use ENTER_FRAME In A Timer?
Here's a piece my code:
ActionScript Code:
var imageTimer:Timer = new Timer(4000,1);
imageTimer.addEventListener(TimerEvent.TIMER, switchImage);
function switchImage(Event:TimerEvent):void
{
images[i].addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
basically, I have a bunch of MC's in an array, and when the timer goes off, it will start the animation to switch images using an EnterFrame event. Yet, when I test the movie, I get this error, pointing at the EventListener in my switchImage function....
1119: Access of possibly undefined property ENTER_FRAME through a reference with static type flash.events:TimerEvent.
What's wrong? Why can't I add an EnterFrame listener when a timer goes off??
Terminate ENTER_FRAME ?
Greetings,
I can't seem to get this to work:
stage.addEventListener(Event.ENTER_FRAME,startUp);
function startUp() {
rowsReq();
columnsReq();
matchDef();
_itemPosition();
if (stopEnterFunc == 1)
{
stage.removeEventListener(Event.ENTER_FRAME);
for (var i=1; i < 17; i++)
{
this['dry' + i]=this["_item" + i + "_drag"].y;
}
for (var j=1; j < 17; j++)
{
this['drx' + j]=this["_item" + j + "_drag"].x;
}
for (var k=1; k < 16; k++)
{
this['_item' + k + "_drag"]._txt.htmlText=dWords[k];
}
}
}
In AS2 this was easier, or so it seems. Just used:
delete this.onEnterFrame;
Any help will be greatly appreciated!
ENTER_FRAME Undefined?
This is the code of a little program I'm working on. It's pretty simple, but when I try to test it the following error occurs: "1119: Access of possibly undefined property ENTER_FRAME through a reference with static type flash.events:MouseEvent." Which is a little strange, considering that I have used almost the same syntax in some other cases and there wasn't any problem. Any help would be appreciated.
ActionScript Code:
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.events.Event;
var Vx:Number = 0;
var Vy:Number = 0;
var a:Number = 0.98;
var h:Number = 0;
var X:Number = 0;
var Y:Number = 0;
var ball:MovieClip = new MovieClip();
ball.x=ball.y=0;
this.addChild(ball);
var mc:MovieClip = new MovieClip();
mc.x=mc.y=0;
this.addChild(mc);
button_submit.addEventListener(MouseEvent.CLICK, EventReceiver);
function EventReceiver(Event:MouseEvent):void{
Vx = v_ns.value;
h = h_ns.value;
X = 0;
Y = 400 - h;
mc.graphics.clear();
mc.graphics.moveTo(0, 387-h);
mc.graphics.lineStyle(1, 0x000000);
mc.graphics.beginFill(0x000000);
mc.graphics.lineTo(40, 387-h);
mc.graphics.lineTo(40, 417-h);
mc.graphics.lineTo(0, 417-h);
mc.graphics.lineTo(0, 387-h);
mc.graphics.endFill();
addEventListener(Event.ENTER_FRAME, startAnimation);
}
function startAnimation(e:Event):void{
if(Y<400){
X += Vx;
Vy += a;
Y += Vy;
ball.graphics.clear();
ball.graphics.beginFill(0x000000);
ball.graphics.drawCircle(X,Y,13);
ball.graphics.endFill();
}
else {removeEventListener(Event.ENTER_FRAME, startAnimation);};
}
Problem With ENTER_FRAME Help Please
Just started migrating and am having problems with the enter frame event.Did a simple rotating star animation with the following code
import flash.events.*;
function rte(event:MouseEvent) {
function rotate(event:Event) {
m_mc.rotation+=40;
}
m_mc.addEventListener(Event.ENTER_FRAME,rotate);
}
b_mc.addEventListener(MouseEvent.CLICK,rte);
When I press the button (b_mc) more than once the star starts rotating faster every time.What is going on?Doesn't happen in AS 2.0
Event.ENTER_FRAME
Hi guys,
If I add an event listener for Event.ENTER_FRAME can it interupt my function ? This is what I mean:
public function myFunction() : void {
a=1;
b=2;
c=3;
// frame gets entered, will it jump to the listener function right here ?
d=4;
e=5;
f=6;
}
Thanks.
ENTER_FRAME Issue
Hi guys, I'm really quite new to actionscript let alone AS3, hopefully you can help me out with an issue I'm having.
I have a movieclip with instance name "Title" within my main timeline. I want to jump to a frame within "Title" labelled "Appear" whenever the playhead reaches a certain frame on the main timeline.
In AS2 I would have gone with onEnterFrame, but I'm not sure what to do with AS3. Here's what I've attempted, but it doesn't seem to work:
Code:
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
trace("MovieClip(root).Title.gotoAndPlay(Appear)");
}
removeEventListener(Event.ENTER_FRAME,myFunction);
Any help you could give would be great.
Thanks!
Better Than ENTER_FRAME For This Project?
I'm not a developer and over the course of the past year during which I've learned a lot of AS3, I have probably not come close to applying what would be considered "best practices." I have lots of code that could probably be dramatically changed to improve performance.
Here's a bit of my code that I'd like advice about. Is there a different technique I can use to do the following, that's more streamlined?
masterCounter is variable that's iterated every tenth of a second on the root timeline. The following code is in a movie clip that's been added to the stage:
PHP Code:
addEventListener(Event.ENTER_FRAME, s003Listener);function s003Listener(event:Event):void { if (!event.target.parent.masterIsPlaying) { pauseAudio(); } if (event.target.parent.masterIsPlaying) { resumeAudio(); } if (event.target.parent.masterCounter == 1) { startAudioBkgd(); } if (event.target.parent.masterCounter == 10) { startAudio01(); } if (event.target.parent.masterCounter == 50) { Tweener.addTween(s003Presented, {alpha:1, time:fade}); } if (event.target.parent.masterCounter == 62) { playWhoosh(); } if (event.target.parent.masterCounter == 65) { s003Presented.gotoAndPlay(2); } if (event.target.parent.masterCounter == 95) { Tweener.addTween(s003Presented, {alpha:0, time:fade}); Tweener.addTween(s003title, {alpha:0, time:fade}); }// ...etc. Imagine there are a hundred of these if statements...
Don't flame me for being a Flash Butcher!
Thanks for any help!
ENTER_FRAME Listeners..
so in an attempt to leave no stone unturned, I need to understand why things happen, when applying an ENTER_FRAME listener, does the code excecute as long as your on the frame, kinda like a loop but with no statement to stop it? for example I have the following code:
var contRotate:Number = 1;
stage.addEventListener(Event.ENTER_FRAME, spinWheel)
function spinWheel(e:Event) {
var bigWheelRotate:TequilaTween = new TequilaTween(bigWheel, {x:90});
bigWheelRotate.start();
bigWheel.x = contRotate + 1;
trace("wheel spinning");
}
the string"wheel spinning" keeps tracing, however,bigWheel doesnt rotate, so do ENTER_FRAMES excecute once, or as long as your on the frame?
Particals + ENTER_FRAME
Hi everyone.
I looked through the posts and don't think this has been covered yet.
I'm creating a smoke trail effect that moves from the left of the screen to the right using particles.
In order to know where to go, and to create a random effect each particle has its own ENTER_FRAME, and they are being created one-per-frame until they are removed at the other end. (this is all done in an external file).
By the time they begin being removed there are hundreds and the app slows down. My guess is that this is due to hundreds of ENTER_FRAMES running simultaneously.
I was wondering if there is any way to use a central ENTER_FRAME in the main file that simply 'fires' a function in all of the existing particles (to make them listen for a command rather than having separate ENTER_FRAME). This would reduce system load and keep individual movement.
Thanks in advance!
James
Conquering ENTER_FRAME :)
touching is a Boolean which is declared as false;
it becomes true in here:
PHP Code:
mc.addEventListener(MouseEvent.MOUSE_OVER, onRollOver); function onRollOver(e:MouseEvent):void { touching = true;}
and then false again in here:
PHP Code:
mc.addEventListener(MouseEvent.MOUSE_OUT, onRollOut); function onRollOut(e:MouseEvent):void { touching = false;}
first of all, i wanted to say it like this:
PHP Code:
if (touching == true) {addEventListener(Event.ENTER_FRAME, scrollMouse);function scrollMouse(e:Event):void { TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)}); }}if (touching == false) {removeEventListener(Event.ENTER_FRAME, scrollMouse);}
But it doesnt work, the listener is never added, dont understand why...
it WORKS like this:
PHP Code:
addEventListener(Event.ENTER_FRAME, scrollMouse);function scrollMouse(e:Event):void {if (touching == true) { TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)}); }}if (touching == false) {}
But it defeats a purpose of adding/removing event listener when not necessary, especially ENTER_FRAME.
how can i make this work so that i add that listener only when i want and remove it accordingly?
i dont want to have ENTER_FRAME on my neck all the time...
|