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?
Adobe > ActionScript 3
Posted on: 12/14/2007 07:44:16 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Error 1061: Undefined Method AddChild... AddChild Problem
1061: Call to a possibly undefined method addChild through a reference with static type flash.displayisplayObject.
Hi, i have searched the forum recently but even i've found some similar problems i could not find any answer that meet my problem.
Well i had a gallery MovieClip and a sprite called photoContainer which i add some thumbs (my thumb class). Everything was perfectly working until i delete my gallery movieClip on the stage and make it a class from the library (class name : Gallery) I wanted to add photoContainer sprite into my gallery using gallery.addChild(photoContainer) so that way i thought when i say removeChild(gallery) both gallery and everything inside it including photoContainer will be removed. But now i can't add anything to my photoContainer sprite which is inside of gallery.
//my working code before i deleted gallery movieclip on stage
ActionScript Code:
var photoContainer:Sprite = new Sprite();
photoContainer.name="photoContainer";
addChild(photoContainer);
photoContainer.addChild(thumb); //perfectly works
photoContainer.mask=gallery.thumb_holder;
//the code i used after i had deleted gallery movieClip
ActionScript Code:
var gallery:Gallery = new Gallery();
addChild(gallery as MovieClip);
var photoContainer:Sprite = new Sprite();
photoContainer.name="photoContainer";
gallery.addChild(photoContainer);
photoContainer.mask=gallery.thumb_holder;
/*
gallery.getChildByName("photoContainer").addChild(thumb); //gives "1061: Call to a possibly undefined method
addChild through a reference with static
type flash.display:DisplayObject."
gallery.photoContainer.addChild(thumb); //gives TypeError: Error #1010: A term is undefined and has no properties.
*/
by the way:
ActionScript Code:
trace("gallery Type : " +gallery); //gallery type : [object Gallery]
trace("photo container type : " +gallery.photoContainer); //photo container type : undefined
trace("photo container type : " +gallery.getChildByName("photoContainer"))
//photo container type : [object Sprite]
it perfectly adds photoContainer to gallery but gallery.photoContainer returns undifined?? or when i use "gallery.getChildByName("photoContainer").addChild (thumb);" it gives error 1061 Can anybody help me?
thanks you very much...
Is There A Way To Add Variable Arguments To AddChild.. Like AddChild(blah, {x:30})?
in AS2 you could so something like:
blah = attachMovieClip("something", "whatever", {_x:30, _y:25, blahVar:90});
and it would immediately position the blah movieclip, and add a variable called blahVar set to 90 within it, which could be accessed like:
trace(blah.blahVar);
is there any way of doing this in AS3? addChild only takes one argument it seems, so i find myself being forced to do crap like this:
addChild(someMovie);
someMovie.x = 20;
and i have absolutely no idea how to add variables to a movieclip either.. does anyone have any idea?
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!
OOP Addchild Problem "undefined Method Addchild"?
Trying to do more OOP...
This is within a Movieclip class in a .as file:
public static function iconLoad(section:String){
var iconLoader:Loader;
iconLoader = new Loader();
var myDispatcher:IEventDispatcher = iconLoader.contentLoaderInfo;
myDispatcher.addEventListener(Event.COMPLETE, completeIconListener);
myDispatcher.addEventListener(ProgressEvent.PROGRE SS, progressIconListener);
iconLoader.load(new URLRequest("photos/"+section+"/icon.jpg"));
trace("photos/"+section+"/icon.jpg");
var image:Bitmap;
function completeIconListener(event:ProgressEvent):void{
image = Bitmap(event.target.loader);
image.smoothing = true;
addChild(image);
image.x = 0;
image.y = 0;
engage();
}
function progressIconListener(event:ProgressEvent){
iconBytesLoaded = event.bytesLoaded;
iconBytesTotal = event.bytesTotal;
}
}
Why do I get this error for addchild()?
1180: Call to a possibly undefined method addChild.
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;
}
}
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
AddChild
PHP Code:
var addStar:starOuter = new starOuter();var StringI:String;var RandomY:Number; for(var i = 0; i <= 50; i++){ RandomY = Math.round(Math.random() * 265); StringI = "Star" + String(i); addChild(addStar).name = StringI; getChildByName("StringI").y = RandomY; }
I use this code, and it gives error.
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/Untitled_fla::frame1()
I realy don't know what is the problem, 'cos i have seen this type of use of getChildByName .
AddChild
Hello all.
I created a xml based menu using display objects.
I create a simple for each loop with every xml entry and then use the addchild method.
The problem is, there is no way to identify the menu item. What I mean, is that every display object has the same name.
I thought that maybe I could use arrays, and create a display object with an id… nothing works.
How on earth can I identify the menu items so that I may then change color with the ColorTransform or use javascript functions??
Here is my loop, just in case (I want to identify the rect45 object):
PHP Code:
var d:int; for each (var item in newBar.menuXML.item) { //CREATES MENU BAR var menu01 = new menuBarItem(); menu01.x = d * 30; menu01.y = -44; menu01.buttonMode = true; addChild(menu01); //CREATES MENU BAR FILL var rect45 = new barTint(); rect45.x = 0; rect45.y = 0; menu01.addChild(rect45); var colorInfo:ColorTransform = rect45.transform.colorTransform; var themeColor = newBar.menuXML.color; function mouseHover(event:MouseEvent):void { colorInfo.color = themeColor; rect45.transform.colorTransform = colorInfo; } function mouseLeave(event:MouseEvent):void { colorInfo.color = 0x616161; rect45.transform.colorTransform= colorInfo; } rect45.addEventListener(MouseEvent.MOUSE_OVER, mouseHover); rect45.addEventListener(MouseEvent.MOUSE_OUT, mouseLeave); //CREATES MENU BAR TEXT AND EMBEDS FONT FOR ROTATION var menuTitle:TextField = new TextField(); menuTitle.text = item.label; menuTitle.x = d * 30 + 15; menuTitle.y = 75; menuTitle.embedFonts = true; menuTitle.rotation = -45; menuTitle.setTextFormat(format); menuTitle.width = 105; menuTitle.selectable = false; menuTitle.mouseEnabled = false; addChild(menuTitle); d++; }
What Exactly Does AddChild Do?
i know what defining a class does.
but what i dont kunderstand is, why you have to say this:
PHP Code:
var yourObject:YourClass = new YourClass;
AND
PHP Code:
addChild(yourObject);
the first code instanciates the class, right? why addChild?
what happens if u dont use addChild, but just the first part?
and what happens if u use addChild twice?
AddChild
I am new to as3 so this may sound like a silly question...
I want to be able to display the number result of the variable 'moneycounter' on the stage. If I trace the string 'total' I get the right results but why can't I put it on the stage?
var moneycounter:Number = 0;
var total:String = new String();
total = String(moneycounter);
stage.addChild(total);
error
1067: Implicit coercion of a value of type String to an unrelated type flash.displayisplayObject.
AddChild?
Hi,
Im trying to addChild to stage inside a container but nothing appears on the stage, what do I need to do, and what do I need to do to the artwork MCs so the AS picks them up?:
var container1:MovieClip = new MovieClip();
container1.addChild(artwork1);
container1.addChild(artwork2);
container1.addChild(artwork3);
AddChild? MC?
How do I add an MC from my library to the stage using and external AS file?
AddChild()
I am pretty much making a slide show for the most part. I am adding every image to my movie clip that I have loaded from an xml file. So every image that I load goes straight into my movie clip as so:
Code:
m_bSmoothImage = Bitmap(m_cMovieInstance.GetImage(m_iIndex).content);
m_bSmoothImage.smoothing = true;
m_aBmpArray.push(m_bSmoothImage);
m_iIndex++;
m_mcFrames.addChild(m_aBmpArray[m_iIndex]);
My question is after I add all of my images to my movie clip how do I go about showing them? By using addChild() for every new image that I load will show which works great but I don't know how to say start the slide show all over again without re-adding them.
OOP AddChild
Hi. Newb here with a couple of questions if I may...
I've just started out with AS3 and am having a bit of a problem managing the stage. I've made a base class called "Baddy" for all my enemies, and am trying to make an "AddToScene" member that basically adds a Baddy to the stage's main display list.
However, I don't know where the hell I should actually get the stage variable from so I can call addChild on it to make my Baddy visible. My Baddy class inherits Sprite but it's obviously not the one in there.
I think the code I'm looking for is globalsomething.stage.addChild(this); or something.
I thought I'd work around this for now whilst I find my feet and just not inherit Baddy from Sprite and use .graphics to draw a box, but of course there isn't a global .graphics either.
Is it common practice to put the Main class into a global and deref that all over ? Doesn't seem very OOP.
Is there a standard book I need ? I bought "ActionScript 3.0 Animation" on reccomendation but found it wanting. I've been a game programmer for 20 years so don't need to know about springing and collision detection, but I clearly need much help with the absolute basics of the language/environment itself.
I know this is fundamental, but I'm stumped a bit. Any help would be gratefully received, thanks.
Help Me With AddChild()
I'm making a class that will draw box. The class is created through instances and is not the document class. For some reason I can't get it to show anything.
I'm guessing my problem is that I haven't attached my_sprite to something that is being displayed.
PHP Code:
package {
import flash.display.Sprite;
import flash.display.Shape;
public class Make_box {
private var container:Sprite;
private var my_sprite:Sprite;
public function Make_box() {
container = new Sprite();
my_sprite = new Sprite();
my_sprite.graphics.beginFill( 0x660000 );
my_sprite.graphics.drawRect( 0, 0, 100, 140 );
container.addChild( my_sprite );
container.x = 275;
container.y = 200;
}
}
}
|