Event Bubbling Confusion
Hi all.
Ok, i have made a custom event like so:-
Code:
package {
import flash.events.Event;
public class ViewChangeEvent extends flash.events.Event
{
public static const VIEW_CHANGE:String = "viewChanged";
public var _viewID:Number;
public function ViewChangeEvent(viewID:Number,type:String,bubbles:Boolean = true, cancelable:Boolean = false)
{
super(type,bubbles,cancelable);
this._viewID = viewID;
}
}
}
In another class (which is a child of stage) i dispatch the event like this:
Code:
var vEvent = new ViewChangeEvent(ViewChangeEvent.VIEW_CHANGE,_viewID);
dispatchEvent(vEvent);
I have a listener on stage which works works fine:-
Code:
addEventListener(ViewChangeEvent.VIEW_CHANGE,viewChangeHandler);
So far so good, but i have another class, an instance of which is on the stage and it does not receive the event. In the class i have exactly the same as stage. I am a little confused as i thought the event bubbled from stage down to all children?
Actionscript 3.0
Posted on: Tue Jul 22, 2008 2:54 pm
View Complete Forum Thread with Replies
Sponsored Links:
Event Bubbling
Hi there,
AS2 doesn't have an event bubbling model. Does this mean there's no way to detect clicks on anything than the top-most movieclip?
In which case, AS3 is my only option?
Thanks,
Dave
View Replies !
View Related
Event Bubbling
Hi.
I have huge confusion on event bubbling.
The concept is:
I have a "search area" where in I give some criteria and do search.
I have a button called "Search" and on click event I should get the list of data matching with the given criteria in a different container say panel.
Now the question is:
Can I use Bubbling concept for this and how?
View Replies !
View Related
Event Bubbling
Hi,
Please let me know if this doesn't make sense...
I'm developing a series of sequencing classes. SequenceList has an array of Sequences. Each Sequence has an array of Steps. Each Step has an array of Conditions.
A Step dispatches a custom event (with bubbles set to true) when one of its conditions have been satisfied.
The parent Sequence doesn't receive the event unless I add the listener directly to the Step.
Inside class Sequence:
Code:
_array[_index].addEventListener...
Why doesn't the following work?!? Doesn't the event bubble to the Sequence because it originates from a item stored in a array property of the class?
Inside class Sequence:
Code:
this.addEventListener...
More importantly:
The document class contains the SequenceList intance(s). It controls which instance is active. I need to addEventListener directly to the SequenceList instance and have it receive events dispatched from any Sequence or Step. Shouldn't this work based on bubbling? What am I missing here?!?
View Replies !
View Related
As3 Event Bubbling
I've tried to find out more about what this means and how it works. Does bubbling go up a via parent of does it go up the event class? Can any give an example of when you would/would't use event bubbling? Thanks for your help!
View Replies !
View Related
Event Bubbling
So, I have an event with bubbling set to true, and I have a listener on an abstract "Page" Class and a listener for the same event on the concrete class (ExamplePage) that extends that "page" class. The event is fired from a child of the ExamplePage, why is it heard FIRST on the abstract class?
Shouldn't the concrete class extending the abstract class receive the event first?
I would like to have default actions on the abstract class and custom actions on the concrete class but in some scenarios, stop propagation of that event from bubbling up to the abstract class.
View Replies !
View Related
Small Event Bubbling Question
So, if you look at the attached file you'll see that I would like to receive and interpret ROLL_OVER events from the button layered two children down into the movie clip on the stage. With event bubbling, that's easy enough to do with just a simple addEventListener. Unfortunately though, you'll notice that I'm receiving *two* mouse events, one from the button and one from the clip holding it. I don't really want an event from the one holding the button. I can work around it, but it's just noise that I have to account for in my code, and it's bothersome.
Is there some quick and easy way I can make that movie clip that holds the button stop dispatching ROLL_OVER events?
View Replies !
View Related
Event Bubbling, Workaround: Delegation
After reading senoculars button event caputuring (http://www.senocular.com/flash/tutor...ttoncapturing/)
I have been trying to get something to work using workaround #1 and I need some help.
I am trying to get a sound control tab (see attached file) to have a rollOver state which slides in and have buttons on tab be usable but cant seem to grasp the AS needed.
This is the AS but I know it is incorrect because it is not can anyone please help so that I can grasp this concept?
Code:
this.soundtab_mc.play_mc.onPress = function() {
_parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
soundtab_mc.onRollOverHandler()
/// How can I have this function for soundtab_mc work along with buttons within this MC?
/// this.gotoAndPlay(2);
/// }
/// soundtab_mc.onPressHandler() {
/// this.gotoAndPlay(15);
/// }
};
this.soundtab_mc.stop_mc.onPress = function() {
_parent.sound_mc.sound_obj.stop();
soundtab_mc.onRollOverHandler()
};
this.soundtab_mc.next_mc.onPress = function() {
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
soundtab_mc.onRollOverHandler()
};
this.soundtab_mc.prev_mc.onPress = function() {
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
soundtab_mc.onRollOverHandler()
};
stop();
Thanks for any suggestions. MT
View Replies !
View Related
No Event Bubbling Through Animated Bitmaps
bubbling events through a hierarchy of nested DiplayObjects works in many cases but
unfortunately it does seem to work not in all cases:
Given some nested Objects like so:
box = new Sprite();
box.addChildAt(containerA,0);
box.addChildAt(containerB,1);
box.addChildAt(containerC,2);
whereas containerA has some "clickable" Objects inside.
If containerB/C contain bitmaps, for instance, the event bubbling works.
But if containerB/C contain a bitmap with a bitmapData which is manipulated via setPixel
or other pixel changing methods, there is NO event bubbling any more.
My first guess was that has something to do with lock() or unlock() the bitmapData, But it hasn't.
Does someone know why there is no event bubbling in such a case
Keith
View Replies !
View Related
Event Propagation/bubbling Question
i can't doubleclick on an mc with mc's init...the main container mc won't register doubleclick events(it does so with single clicks)...is this a propagation issue and what can be done?(some property or method)...and i cant wrap my head around event bubbling(phases and such)...i guess this and the doubleclick hick up are connected , no?...many thanx for any replies
View Replies !
View Related
Senoculars Event Bubbling With Buttons Issue
Here's some neat coding developed by senocular (thanks a lot!), that "allows child clips to receive events despite the fact that a parent might make use of them as well, something not possible with the normal convention of handling button events where no child movie clip ever receives button events if a parent has any button event handlers defined for it."
Yeah! It's neat.
But I can't really figure out how to attach an event to an mc called "child_next" within "parent1".
Can anybody help me out?
Code:
import com.senocular.events.*
function handleEventMethod(eventObject:ButtonEvent):Void {
// trace event
if (eventObject.type != "onMouseWithin") trace(eventObject.type +"("+this+")");
// stop event from bubbling up to parent clips if this clip is parent2.child
if (this.target == parent2.child) eventObject.stopPropagation();
// react based on which event is being received.
switch(eventObject.type){
case "onRollOver":
case "onDragOver":
// this.target.gotoAndStop(2);
this.target.play();
break;
case "onDragOut":
case "onRollOut":
case "onReleaseOutside":
// this.target.gotoAndStop(1);
this.target.play();
break;
case "onMouseWithin":
break;
//
}
}
// clips to receive events from ButtonEventHandler
var clips:Array = [parent1, parent1.child_prev, parent1.child_next];
var clip:MovieClip;
var buttonEventObj:ButtonEvent;
// allow events to pass through despite overlapping
ButtonEventHandler.overlapBlocksEvents = false;
// assign handleEventMethod as handleEvent handler for each clip in clips
for (clip in clips) {
// get ButtonEvent object for each clip and assign handleEvent function
buttonEventObj = ButtonEventHandler.getEventObject(clips[clip]);
buttonEventObj.handleEvent = handleEventMethod;
// for parent1, set overlapping to block events
if (clips[clip] == parent1) buttonEventObj.overlapBlocksEvents = true;
// enable the hand cursor by providing a null onPress event handler
clips[clip].onPress = null;
}
View Replies !
View Related
Type Coercion Failed -- When Bubbling A Custom Event
I have a main actionscript app that loads a separate SWF file. The loaded swf file dispatches an event when a button is clicked. The event, however, is a custom event of a type that is in an external library (the type is mf.events.LocaleEvent).
Both the main actionscript project and the loaded swf file reference the same external library when referencing the event, but when the main project receives the event from the loaded swf, it throws the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert mf.events::LocaleEvent@2e1e7891 to mf.events.LocaleEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at BottomSkin_fla::MainTimeline/buttonClicked()
Any ideas on how to make the app realize that both swfs are really pointing to the same class?
Thanks in advance for the help!
View Replies !
View Related
Event Confusion
Hi,
I am having some trouble with events. I have a MyComments class that uses a loader to import comments from MYSQL using php and xml. The problem is that because the MyComments class uses an event listener the trace(comm1.toString()); is executing before, the importComments ends.
As a temporary fix I thought that I could insert a timer at //NOTE 1 and get the timer to call the trace statement after 5 seconds or some fixed amount of time. This does not seem like a good solution.
Is there anyway that I can make a new event in the MyComments class that will fire after the importComments() function ends? That way I could put the trace statement in an event handler.
var comm1:MyComments = new MyComments();
comm1.importComments(); //uses a loader.
//NOTE 1
trace(comm1.toString());
thanks guys.
View Replies !
View Related
Mouse Event And Confusion
I have a 20x20 grid of circles all using the same movieclip. It basically duplicates one movie clip to build the grid when the flash movie is run.
I need these circles to change color when you hold the mouse down and drag over them. I want to simulate a paint brush to get the idea that you are painting the circles while the mouse is held down.
I am having trouble, it seems that I can get it to change color when you click or mouse over, but I can't get it to do both at the same time.
The only way I got this to work was to do a hit test with a movieclip attached to the pointer. Well this is 400 loops all executing at the same when the mouse down occurs, and slows the movie down significantly.
Any help would be grateful!!
View Replies !
View Related
A Confusion About Event Dispatch
dear all,now i have a Display List just like:
Code:
stage
-myswf.swf
- mycontainer1
- child1
- child2
- mycontainer2
- child3
- child4
when i click child1 in mycontainer1, i want to dispatch a event and notify child3 to do something,so, in child3, i add listener like
ActionScript Code:
public class Child3
{
public function Child3()
{ this.addEventListener(SlideChangeEvent.SLIDE_CHANGE,slideChangeHandler);
//SlideChangeEvent is a custom event
}
private function slideChangeHandler(event:Event):void
{
trace("in this");
}
}
and in child1 , i add code that dispathevent like
ActionScript Code:
public class Child1
{
public function Child1()
{
this.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
}
private function mouseUpHandler(event:MouseEvent):void
{
dispatchEvent(new Event(SlideChangeEvent.SLIDE_CHANGE));
}
}
when i click child1 , i think child3 should be notify, and trace "in this",but i fact, it is not. does my way is a wrong use of event? and if i want to dispath event like child1 and child3, what should i do?
thx.
View Replies !
View Related
ASBroadcasters / Event Dispatchers Confusion
AS2 newbie question here:
I've been going round and round in circles trying to work out the best way of doing this, so maybe someone can help me.
I've tried in vain on several occasions to get my head around ASBroadcasters / Event Dispatchers, but I'm not even sure that they are what I'm looking for.
Let's say I have a movieclip on the main timeline of my fla called acrobat_mc which is an animation of a little man doing a somersault.
I also have a bunch of movieclips of audience members each controlled by thier own instance of an AudienceMember object. The AudienceMember object contains a method called applaud().
When the acrobat has finished doing his somersault, I want all the instances of audienceMember to have their applaud methods triggered.
Now obviously, I could put a whole bunch of commands on the final frame of my somersault animation such as:
ActionScript Code:
_parent.audienceMember1.applaud();
_parent.audienceMember2.applaud();
_parent.audienceMember3.applaud();
etc.etc....
But what I really want is to just broadcast some message from that frame on the acrobat's timeline that makes all the audience members automatically applaud.
How should I be doing this?
Cheers.
View Replies !
View Related
XML Menu Loop / Event Handler Confusion
Hi
this one is doing my head in, it's probably a real basic one for you guys but I've been scouring the net last 2 days banging my head trying to find a solution.
I'm pulling in data from an external XML file e.g.:
<resources>
<resource>
<siteName>This Site</siteName>
<siteThumb>img/img1.png</siteThumb>
<url>http://www.yahoo.com</url>
</resource>
<resource>
<siteName>That Site</siteName>
<siteThumb>img/img2.png</siteThumb>
<url>http://www.google.com</url>
</resource>
</resources>
No problem there that's all loading in fine. I have a movie clip (linkBox) in my library linked with class LinkBox, inside the movie clip there is a textfield called dataBox. I'm using:
ActionScript Code:
function ParseResources(resourceInput:XML):void{
var resourceChildren:XMLList = resourceInput.resource;
for (var i:int = 0; i < resourceChildren.length(); i++) {
var linkBox:LinkBox = new LinkBox();
linkBox.x = 10;
linkBox.y = i * 20;
linkBox.dataBox.text = resourceChildren[i].siteName;
addChild(linkBox);
linkBox.addEventListener(MouseEvent.CLICK,getSite);
}
}
Which is all fine and groovy I end up with a batch of movie clips all lined up containing the relevant link text.
The problem arises when I'm trying to get them to link to what they are supposed to link to (which is in linkBox.dataBox.text = resourceChildren[i].url; or url in the XML file).
ActionScript Code:
function getSite(event:Event):void
{
//BIG FAT VACANT STARE
var siteLink:URLRequest = new URLRequest(?????);
navigateToURL(siteLink);
}
With my currently limited development knowledge I'm outside of the original loop so whatever goes in that loop is no longer relevant within this new event handler. I've tried every way I can think of to try to target one of the movie clips in my stack. I've tried sticking the instances in an array and referencing them but the array thing doesn't like being inside an XML function apparently (or I'm doing it wrong). Anyway I won't bore you with what hasn't worked, if anyone has got a solution as to how one would go about setting the getSite handler set up to do what I'm trying to get it to do I would be very grateful.
Thanks for reading.
Edward.
View Replies !
View Related
Bubbling
I was tracing out a Timer Event and saw that there were a few values I hadn't known about - one was bubbling, and it was set to false.
What's bubbling, and why would I use it in the instance of a timer?
Seems cool, my n00b programmer eyes just haven't seen that word before.
Thanks!
View Replies !
View Related
Bubbling?
I think my problem is called bubbling. I've tried reading Essential Actionscript 3 but being Dyxlesic making sense of isn't the easiest thing to do!
I'm trying to control a container - containing all my menus, I know the code works as I have used it else where in my project.
Could some kind soul also tell me what the heck it is in plain English.
Code:
//AT VERY TOP OF DOUCMENT CLASS >
public var _mainContent:*;
public var _contentSelect:*;
public var _menuActive:*;
public var _menuSystem:*;
function contentStart():void
{
trace ("contentStart");
TweenMax.to (_mainContent, 1,{ autoAlpha:1, onComplete:openMe});
}
function openMe ():void
{
_menuSystem = site.mainContent.mContainer;
for (var i:Number = 1; i < _menuSystem.numChildren; i++) {
_contentSelect = _menuSystem.getChildAt(i);
_contentSelect.addEventListener(MouseEvent.MOUSE_OVER, myMouseOver);
_contentSelect.addEventListener(MouseEvent.MOUSE_OUT, myMouseOut);
_contentSelect.addEventListener(MouseEvent.CLICK, fadeDown);
_contentSelect.buttonMode = true;
}
}
Regards
Mat
View Replies !
View Related
Bubbling Pointers?
How do you make the pointer of the mouse look like it is trailing things like bubbles or flowers etc.? an example of this is http://www.barbie.com where flowers trail the mouse.
View Replies !
View Related
[as3] Bubbling Only For DisplayObjects?
I just have a simple question. Does event bubbling only work for DisplayObjects or classes extending DisplayObject? Do all of the objects being bubbled through need to be added to the display list as well?
I'm using Flex 3 and right now I have an ArrayCollection containing Deck's (Deck also extends ArrayCollection) which contains Cards (extending nothing). For an event to bubble from a Card to the main Application does each of those classes then have to extend a DisplayObject in some form and be added to the display list? I would like to then catch any CardEvents, say, on the main Application with the code this.addEventListener(CardEvent.MYCARDEVENT, cardEventHandler).
And incidentally, if it's true that only DisplayObjects can bubble events, why is this so? It seems like it would be handy to bubble events in any class.
View Replies !
View Related
Exception Bubbling And Events
i have a try-catch statement that i want to use to load an image.
here is the stripped down functionality:
// actionscript
this.onLoadError = function() {
throw new Error("onLoadError");
};
mcloader = new MovieClipLoader();
mcloader.addListener(this);
try {
mcloader.loadClip("fdjk.jpg", createEmptyMovieClip("test_mc", 1));
} catch (e) {
trace('Error = ' + e)
}
// end actionscript
if the image doesn't load, i'd like to throw an error, but the onLoadError function is outside the scope of the try and therefore the throw will not find the catch.
is there ANY way to get something like this to work????
View Replies !
View Related
Preventing Clicks From Bubbling Through Movie
I have a tree menu that serves as a file explorer. Users can click on the icon next to an item's label to call up a context menu for that item. I have a problem in that when the context menu is displayed (on top of the tree) the clicks seem to pass right through the context menu to the tree, firing events.
How can I keep this from happening????
View Replies !
View Related
Child Propagation/bubbling Problem?
I'm in one heck of a pickle. I informed a client that i could build them this nifty little flash menu expecting that I would be able to figure out the process fairly easily. I'm passed the deadline, but bought myself time until tomorrow. Any help here would be oh-so awesome.
my fla is here: http://www.d-w-t.com/pom5.fla
If you test it, you can roll over 'about us' and a menu slides down. The problem is, this menu is completely non-functional. The item you roll over is supposed to turn black and take you to a link when you click on it. I havn't even gotten to turning it black because the actual link never works (currently, only 'our story' is set up). According to the rules of child propagation and bubbling, I think it should work - but I am, alas, a noob and obviously don't have a full understanding. The reason I feel it should work is because the on(rollOver) of the 'about us' works and that's in the same movie clip as the on(press) (and go to a url) button... so why would one work and not the other if the rules of child propagation/bubbling are preventing it...?
Please help. I'm desperate. Thanks.
View Replies !
View Related
Events Bubbling Out Of Custom Classes?
Okay, I'm trying to create a job queue type of system that uses event bubbling so that events can be dispatched from multiple locations and bubble up to a front controller.
For some reason my EventHandler is never being called:
OUTPUT:
DataPack Constructed
Custom Event Constructed
EventTransporter Constructed
Dispatching event type: _dataevent
Does anyone see anything terribly wrong here?
TestEvents.as
Code:
package {
import flash.display.Sprite;
public class TestEvents extends Sprite
{
public function TestEvents()
{
addEventListener(CustomEvent.DATA_EVENT, onCustomEvent);
var myCaller:EventCaller = new EventCaller();
var myData:DataPack = new DataPack([1,2,3,4,5]);
var event:CustomEvent = new CustomEvent(CustomEvent.DATA_EVENT, myData);
var holder:EventTransporter = new EventTransporter(event);
myCaller.callEvent(holder);
}
private function onCustomEvent(event:CustomEvent):void
{
trace("onCustomEvent data: "+event.data);
}
}
}
DataPack.as
Code:
package
{
public class DataPack
{
private var _stuff:Array;
public function DataPack(ary:Array)
{
trace("DataPack Constructed");
_stuff = ary;
}
public function get stuff():Array { return _stuff }
}
}
EventCaller.as
Code:
package
{
import flash.events.EventDispatcher;
[Event(name="_dataevent", type="CustomEvent")]
public class EventCaller extends EventDispatcher
{
public function EventCaller() {}
public function callEvent(holder:EventTransporter):void
{
trace("Dispatching event type: "+holder.event.type);
dispatchEvent(holder.event);
}
}
}
EventTransporter.as
Code:
package
{
public class EventTransporter
{
private var _event:CustomEvent;
public function EventTransporter(event:CustomEvent)
{
trace("EventTransporter Constructed");
_event = event;
}
public function get event():CustomEvent { return _event }
}
}
CustomEvent.as
Code:
package
{
import flash.events.Event;
public class CustomEvent extends Event
{
public static const DATA_EVENT:String = "_dataevent";
private var _data:DataPack;
public function CustomEvent(type:String, data:DataPack)
{
trace("Custom Event Constructed");
super(type, true);
_data = data;
}
public function get data():DataPack { return _data }
}
}
View Replies !
View Related
Child Propagation/bubbling Problem?
I'm in one heck of a pickle. I informed a client that i could build them this nifty little flash menu expecting that I would be able to figure out the process fairly easily. I'm passed the deadline, but bought myself time until tomorrow. Any help here would be oh-so awesome.
my fla is here: http://www.d-w-t.com/pom5.fla
If you test it, you can roll over 'about us' and a menu slides down. The problem is, this menu is completely non-functional. The item you roll over is supposed to turn black and take you to a link when you click on it. I havn't even gotten to turning it black because the actual link never works (currently, only 'our story' is set up). According to the rules of child propagation and bubbling, I think it should work - but I am, alas, a noob and obviously don't have a full understanding. The reason I feel it should work is because the on(rollOver) of the 'about us' works and that's in the same movie clip as the on(press) (and go to a url) button... so why would one work and not the other if the rules of child propagation/bubbling are preventing it...?
Please help. I'm desperate. Thanks.
View Replies !
View Related
Newbie..needs Some Help And Explaination On Possible Bubbling(sp?) Problem In Submenu
Hi. First post of course it's a problemquestion. I've spent around five hours reading forums and help topics and I believe I have a bubbling (sp?) problem and I am obviously not sure how to fix it.
I'll be specific as possible and you can look at the page here
http://www.financialmanagementgroupl...ment_menu.html
and download the FLA zip here
http://www.financialmanagementgroupl...ement_menu.rar
My problem is this:
I have created a menu on scene 1 in a movie clip
inside the clip I have created the buttons for the main menu and 2 sub menus as movie clips the sub menus are called up by labels on rollover of thier parent buttons on the main menu. I need the parent button (Project Advice) to be clickable as well as the sub menu buttons. However at this point I can not get the submenu buttons (the New England button (new_btn)) to properly link to a label in scene one (New England). Any help or explaination would be awsome, or even just a quick link to a good tutorial/info about the problem. Thanks for any help.
EDIT: I just wanted to add that I was following a tutorial from learnflash.com that told me to build a menu this way, but did not explain how to create links in the submenu.
-J. Sheehan
View Replies !
View Related
Newbie..needs Some Help And Explaination On Possible Bubbling(sp?) Problem In Submenu
Hi. First post of course it's a problemquestion. I've spent around five hours reading forums and help topics and I believe I have a bubbling (sp?) problem and I am obviously not sure how to fix it.
I'll be specific as possible and you can look at the page here
http://www.financialmanagementgroupl...ment_menu.html
and download the FLA zip here
http://www.financialmanagementgroupl...ement_menu.rar
My problem is this:
I have created a menu on scene 1 in a movie clip
inside the clip I have created the buttons for the main menu and 2 sub menus as movie clips the sub menus are called up by labels on rollover of thier parent buttons on the main menu. I need the parent button (Project Advice) to be clickable as well as the sub menu buttons. However at this point I can not get the submenu buttons (the New England button (new_btn)) to properly link to a label in scene one (New England). Any help or explaination would be awsome, or even just a quick link to a good tutorial/info about the problem. Thanks for any help.
EDIT: I just wanted to add that I was following a tutorial from learnflash.com that told me to build a menu this way, but did not explain how to create links in the submenu.
-J. Sheehan
View Replies !
View Related
MovieClipLoader OnLoadInit Event AND Loader Component Complete Event
What´s the difference beetwen the Loader complete event and MovieClipLoader onLoadInit. The manual says onLoadInit is called after the code on the first frame of the loaded clip gets executed, so, it´s better to use onLoadInit if you want to manipulate the loaded asset via code.
So, if anyone could clarify the following points to me, I would be grateful!
- Does the complete event of the Loader component have the same behaviour?
- How does MovieClipLoader knows that the code on the first frame of the loaded assets got executed?
Thanks,
Marcelo.
View Replies !
View Related
Custom Event Handlers - Triggering Event Listeners On Other Objects
I'm trying to update an object whenever something happens in another object. At the moment, I have the second object explicitly calling an update function on the first object, but this seems a little sloppy and it strikes me that this is the sort of scenario where I should be using custom event handlers.
I'm not quite sure how they work though. My first assumption is that if I built two objects, one like this which fires off an event:
Code:
public class eventFirer extends Sprite
{
public function eventFirer():void
{
dispatchEvent(new Event("customEvent"));
}
}
...and one like this which updates whenever the custom event happens:
Code:
public class eventListener extends Sprite
{
public function eventListener():void
{
trace ("main");
addEventListener("customEvent", eventFired);
}
private function eventFired(e:Event):void
{
trace ("ok");
}
}
...then eventListener.eventFired would automatically be set off whenever a new eventFirer is created. This seems not to be the case though.
Can anybody enlighten me as to how custom events bubble between otherwise unrelated objects?
View Replies !
View Related
Passing Parameters From Event Listener To Event Handler
Hi Chaps,
First of all, apologies as I know this question has been asked before, but I have spent the last twenty minutes reading this thread and still can't seem to figure out how to apply it to my situation - probably because I'm thick!
I have a number of objects which need to be rotated according to different parameters. I have a function which takes those parameters, then uses the tween class to handle the rotation. I'm then using the tweenEvent class to check for when the motion is complete. Then, I need access to those same parameters in the complete handler to do further operations. The problem I have is that the tween event class doesn't allow me to pass the parameters along to the cpmpleteHandler, so I'm stuck getting my parameters from the first function to the second function:
Code:
function rotate(parameters){
rotationTween = new Tween(object,parameter1,parameter2,........);
rotationTween.addEventListener(TweenEvent.MOTION_FINISH,completeHandler);
}
function completeHandler(e:TweenEvent){
//need access to the paremeters passed into the first function here!!
}
From reading the thread mentioned above, I have a feeling I may need a custom class to do this - please don't laugh but I've never written (or had the need to) write my own class before, so I really wouldn't know what to do. Any help greatly appreciated, but an actual code snippet which demonstrates this would be even better!
Ric.
View Replies !
View Related
Event Listener Mouse Event Click - Obstructions
This is an oversimplification of my problem.
I have an event listener on a sprite.
I then have portions of this sprite covered with other sprites or moveclips.
If I click a movieclip, it blocks my eventlistener on the sprite underneath it.
Is it possible to listen to the even click 'through' a movieclip. I dont want interaction with them, but I dont want them as bitmap data onto the base sprite either...
View Replies !
View Related
I Don't Understand The Keywords: This, Event.target, Event.currentTarget
I am almost a complete beginner to Actionscript 3.0.
I've been looking at tutorials and I now understand most of the basic principles and methods of this programing language (creating basic functions ect..).
However I do not understand the following keywords.
1. this
2. event.target
3. event.currentTarget
What do these words refer to?
How are they different from each-other?
When must i use them?
View Replies !
View Related
Event Propagation Vs. Event Blocking -- Confused, Even After Moock
I thought I understood the AS3 event scheme: capture, target, bubbling. That events (e.g. MouseEvents) travel from stage to the object clicked on and then back again, and all objects in the display chain receive and can check that event. But it's also true, it seems, that Interactive Objects in front of others will block and "absorb" events, and those beneath will never hear of the event (unless mouseEnabled for the blocking object is set to false). I don't understand this (seeming) contradiction.
On the Kirupa forums:
Along with event propagation in ActionScript 3 comes different phases of events with display objects. With propagation, you have events being propagated from display objects to other display objects, such as mouse click events being propagated from children to their parents. This lets clicks within children objects to be recognized by parents (since children make up the contents of their parents, its only natural for the parent to also have those same events). The phases of such an event represent the progression of the event as it makes its way through the parent and child objects.
Events actually start with parent objects (phase 1: capturing), starting with the top most parent (stage) and making its way down to the child where the event originated (phase 2: at target). Then after reaching the child it makes its way back up through all the parents again (phase 3: bubbling).
But also:
Though ActionScript 3 now supports event propagation (capturing, bubbling, etc). Events like mouse events still only occur for one specific target for each individual event. In other words, when you click the mouse button over some objects in a Flash movie, only one of those objects is going to recieve the event even though the mouse is physically over other objects as well.…One important thing to keep in mind is that, in ActionScript 3, mouseEnabled is true by default. This means, without any event handlers or listeners used in a movie, every InteractiveObject instance will capture mouse events and prevent them from reaching any other objects beneath them.
Any clarification much appreciated…
View Replies !
View Related
Confusion
ok ,,, so ,,, i have 5 input text boxes.
worldpay_vars is an MC on the single framed timeline. This had to be because of the worldpay system.
anyway,,,
these are on the actions layer
this.worldpay_vars.ref = ref.text;
this.worldpay_vars.name = name.text;
this.worldpay_vars.business = business.text;
this.worldpay_vars.tel = tel.text;
this.worldpay_vars.address = address.text;
this.worldpay_vars.postcode = postcode.text;
this.worldpay_vars.email = email.text;
this.worldpay_vars.amount = "25";
this.worldpay_vars.country = "GB";
this.worldpay_vars.instId = "11111";
this.worldpay_vars.cartId = "test";
this.worldpay_vars.currency = "GBP";
this.worldpay_vars.testMode = "0";
this.worldpay_vars.desc = "Legal Protect";
the button has this
on (press) {
this.worldpay_vars.getURL("https://select.worldpay.com/wcc/purchase", "_blank", "POST");
}
The question is ,,,,,, why wont it pass what the customer enters into the input boxes. It only works if I use VAR names instead of INSTANCE names....
am i doing anything wrong?
thanks
View Replies !
View Related
If Else Confusion.
I am using tons of if's and else if's and stuff for a game I'm making. I want to understand exactly how Flash steps through these.
Here is what I think it is: if a condition is met, it doesn't do any of the accompanying else's or else if's. If it isn't, it steps through the else's until one is met and than it doesn't step through the rest. Also what does _totalframes evaluate to if the MC doesn't exist? I've been trying to dynamicly put a stop() on the last frame of an animation with
Code:
if (hero.rise._currentframe==hero.rise._totalframes) {
//whatever
}
So please help?
View Replies !
View Related
Big Confusion Can Anyone Help Me?
Hi there!
I'm trying to make things work without using the "clip.onPress" order, because this way my buttons are disabled.
Can somebody check my fla file and give me some instructions?
http://www.oneplusdesign.com/menu02.fla
Thanks in advance.
View Replies !
View Related
FLV Confusion
I've been searching many threads here and also help files on Adobe.com, and it seems many people are experiencing this and similar problems with flvs.
Could someone who knows what they're talking about explain why sometimes the video will play locally, but not from the server? I've heard musings about some servers not supporting the flv mime type, and other things about perhaps registering the type with IIS, but nothing very conclusive.
If someone could clear this up once and for all I'm sure I'm not the only one who would be extremely grateful!
View Replies !
View Related
THIS Confusion
I am really confused about the use of the word "this". I am sort of aware of the scope issues, being local to a function or refering to the class. So my ? is, i have a
class Practical extends Mover(){
function Practical(targetMC:MovieClip){
super(targetMC);
}
function startMoving(){
this.targetMC.updatePosition=this.updatePosition
}
}//end of class
am i correctly understanding the use of the word 'this' here :
in a fla file i have the following
var myObject:Practical = new Practical();
myObject.startMoving();
when an instance of the Practical class is created, and then calls the startMoving() method from outside the class.
That another method(from Mover class) called updatePosition in
this.updatePosition('this'. then refers to both the classes Practical as well as Mover?? but must be Mover cause the method is defined there and not in Practical).
"this.updatePosition" is then assigned to the Practical Class method called
this.targetMC.updatePosition as it has inherited this method from the Mover class.?? In this instance this refers to the Practical class, even though the property has not been declared in this class file nor has the method been defined.?? Is this right??
And lastly,following on from the above, if i say
class Practical extends Mover(){
function Practical(targetMC:MovieClip){
super(targetMC);
}
function startMoving(){
this.targetMC.updatePosition=this.updatePosition
this.targetMC.onEnterFrame=function(){
this.updatePosition();
}
}
}//end of class
New code included:
this.targetMC.onEnterFrame=function(){
this.updatePosition();
}
The use of the word "this" in the function method ie
this.updatePosition();
refers to the local function and not the class???
Hope someone can help, appreciated
View Replies !
View Related
XML And AS Confusion
Hi
I have a website where all the menu buttons are made in XML and calling up external swf's (also via XML).
for some reason, when i test it, only every 2nd button works effectively.
what could be the possible error in code?
View Replies !
View Related
Confusion
Why can't I dowload the flash player? It always says "download successful", but when I need it on sites such as peekvids.com or spreadshirts.co.uk it always says I need to dowload it again. Can someone help me?
View Replies !
View Related
Xml Confusion
I'm sure this has all been covered, but I'm having a hard time finding it all. I'm trying to figure out using xml in flash for a photogallery because flash isn't really covered in my class at school.
Anyway, I was trying to use the files from this tutorial: http://www.kirupa.com/forum/showthread.php?t=202132
The problem is that the buttons all load across the bottom in a row. I want them to load 2 thumbnails across by 5 down. How do I specify how I want the thumbs to load. I've been playing with this AS forever and I can't seem to figure it out. Are there any other tutorials on xml photogalleries that will make my life easier? Let me know. Thanks.
View Replies !
View Related
A Bit Of Confusion
So, i can store a array of color values in a ByteArray class, isnt it?
There are those 32bit colors and 16bit,without alpha, colors, rigth?
And i supose that each ByteArray item is only 1 byte, wich have 8 bits, so how can it store 16 bit or 32 bit colors?
Something is wrong but i dont know what
View Replies !
View Related
Bit Confusion Here...
Bit confusion here...
In my main swf I create an mc "Base", which loads an swf...containing a preloader with this script in it....I use penner's tweens, with an onMotionFinished...which should tell the loaded swf to play....but I can,t get there, because the _root.play() command makes my main movie play...how can I get to the loaded swf....I used to just tell the _level where the swf was loaded into to play....but there is just a specific depth now...no _level..
help?
ActionScript Code:
Preload_balk_mc.onEnterFrame = function() {
this._xscale = Math.round(_root.getBytesLoaded()/_root.getBytesTotal()*100);
_root.Perc = Math.round(_root.getBytesLoaded()/_root.getBytesTotal()*100)+"%";
BL = _root.getBytesLoaded();
BT = _root.getBytesTotal();
if (BL == BT) {
//_root.play();
var easeType = mx.transitions.easing.Regular.easeIn;
var easeType2 = mx.transitions.easing.Elastic.easeInOut;
LoaderAlpha = new mx.transitions.Tween(Preload_balk_mc._parent, "_alpha", easeType, Preload_balk_mc._parent._alpha, 0, 15);
LoaderY = new mx.transitions.Tween(Preload_balk_mc._parent, "_x", easeType2, Preload_balk_mc._parent._x, 1300, 25);
delete this.onEnterFrame;
LoaderY.onMotionFinished = function(){
_root.play()
}
}
};
View Replies !
View Related
If Then Confusion
im trying to make flash stop when
particular frames come up in a looped animation
im starting with wone framt called "t"
but i have no idea what im doing
this is what im currently trying...
ActionScript Code:
//i hoped it would keep looking
//for the frame t and stopped when
//it reached that there
//first is the name of an instance
//t is a frame label
if(first._currentframe = ("t"));
{
stop();
}
thanks for any help in advance
View Replies !
View Related
The Best Way To Trigger An Event After A Previous Event Has Played.
What would be the best way to trigger an event via button in one movie clip after another event in has played in a different movie clip.
1. Click button in scene 1 on main stage.
2. The background movie (movie2) should scroll the the designated posistion and stop.
3. Then the foreground layer (movie1) should side in over it after the background has scrolled and stop to display information.
Now if you click another button I would like the clip to do this:
1. The foreground layer (movie1) slides back out opposite as it came in.
2. And the the background (movie2) rotates to it's new posistion and stops.
3. The foreground layer slides in same as (movie1) only some other tab and stops.
I'm completely stumped how to do this any help would be greatly appreaciated.
I posted the file here:
http://www.jbowen.com/jbcspage.swf
and
http://www.jbowen.com/jbcspage.fla
If some one could help me out thanks maybe even take a look a the code in the fla document and repost it or explain.
Thanks.
View Replies !
View Related
Using An Event Listeners Function At Will - Event Dispatching?
Hi,
I have a event listener that turns a camera on and off according to how much motion there is:
ActionScript Code:
camera1 = Camera.getCamera(""+Number(aCameraComboBoxes[selComboBoxNum].selectedIndex-1));
aCameras[selComboBoxNum].addEventListener(ActivityEvent.ACTIVITY, activityHandler, false, 0, true);
private function activityHandler(event:ActivityEvent):void {
if(event.activating){
//camera is turning on
}else if (!event.activating){
//camera is turning off
}
}
All of this works but I need a way to rerun the addlistener's function without the camera actual turning on or off. Is there a way for me to use this function, and send it the variable it is looking for?
Thanks
View Replies !
View Related
|