Object Events

Hello,
If you search for Object events (i.e. events that pass objects inside the event itself) you will see many posts suggesting how to make the custom class to pass the information.
My question is this: Why did Adobe not create such an event in the default API? What downside is there to using this method as the main way to pass information between MVC style components? Since they made special events for everything else, and its such a common practice, surely there must be some reason why it wasn’t done.
Thanks in Advance.

The current event implementation is a standard. Retained information would be in the handler. What exactly are you trying to do?

I’m working with multiple MVC components (Model, View, Controller) inside of a main project.
I’ve got a Dial, a Button and a TextBox. (each an MVC just for the example)
When the Dial moves, it sends an event, and in the main class, the TextBox should update its text with the new data from the Dial.

For this to happen normally, (withouth an event object), the handler of the event, would have to set the Model of the TextBox with the data from the model of the Data. However, the models by standard should be private and not directly accessed from outside of the View.

The work around for this is to send an object with the Event, so that when the Dial sends the event, it also sends Data, For example
dialInstance.dispatchEvent(new ObjectEvent(“SEND_DATA”, true, true, {data:dialModel.currentDialInfo, turn:dialModel.currentTurnNumber, player:dialModel.currentPlayer }) );

then the TextBox would have,
texInstance.addEventListner(“SEND_DATA”, handleData);
function handleData(e:ObjectEvent):void
{
myText = "Player " + e.object.player + " Got a " + e.object.data + "On Turn: " + e.object.turn;
}

How do you expect it to work?

um. why dont you just update the data directly ? as in


function myDialMoving(e:Event):void {
  var theCurrentValue = e.target.rotation; //or whatever
  mTextBoxMovie.textArea.text = theCurrentValue;
  // you could even add
  e.updateAfterEvent();
}

It works just fine. That wasn’t my question.

My question is why a custom class is required, and the flash API doesn’t already come with an event class type that does this. Is there something about this method which isn’t ideal for flash?

Is there some reason why creating a public reference to my model or controller and accessing it through the event target function is better?

A similar question would be why the AS3 api doesn’t support a true Singleton structure, but apparently they are fixing that for flash player 10.

Its really just a curiosity and “best practices” question.

[quote=rbnzdave;2333262]um. why dont you just update the data directly ? as in


function myDialMoving(e:Event):void {
  var theCurrentValue = e.target.rotation; //or whatever
  mTextBoxMovie.textArea.text = theCurrentValue;
  // you could even add
  e.updateAfterEvent();
}

[/quote]

Because of the way Model-View-Controler works, I don’t have direct access to the variables.

You can read up on it here

and here
http://www.cairngormdocs.org/tools/CairngormDiagramExplorer.swf

ahhhhhh. I get ya now. I was doing similar things when i was trying to fire an event to get a movie rolling, without writing another function to do it. except i changed the parameter type in the listener function to an object, and then made a dummy object in my function call with the properties i wanted to read.

A bit of a pain in the bum, but then I work with windows so I’m used to dealing with stupid issues that really ought to have been designed more open. Good to hear its being rectified in fp10.

ok, i take that back. what you should be doing is writing your own class to handle it, as mvc is such a weird way of doing things. Granted, I realise its a valid concept and has been around a long time ( in my view that makes it dated and probably completely obsolete ) but the way that sort of relationship is done now is through classes, in pretty much every language that can produce that sort of model. And I also see now its no wonder the accomodation for this sort of interaction wasn’t included in what they produced as a standard. Its creating extra work for extremely little gain if not detriment.

To follow up with what rbnzdave said, the native classes built into Flash Player are not meant to accommodate all use cases. They’re there to provide base functionality on which additional functionality could be built.

Sure, maybe a metadata property could have been added to the Event class to facilitate MVC and other related uses given your implementation. But the same could be said for just about any other class. But then, suddenly you have a bunch of useless objects floating around in your code that serve no purpose. Additionally, do the events that are not used with your MVC approach require that structure for carrying data when they don’t need it? Through extending the Event class, you’re adding functionality that only needs to be where it’s needed.

[quote=senocular;2333562]To follow up with what rbnzdave said, the native classes built into Flash Player are not meant to accommodate all use cases. They’re there to provide base functionality on which additional functionality could be built.

Sure, maybe a metadata property could have been added to the Event class to facilitate MVC and other related uses given your implementation. But the same could be said for just about any other class. But then, suddenly you have a bunch of useless objects floating around in your code that serve no purpose. Additionally, do the events that are not used with your MVC approach require that structure for carrying data when they don’t need it? Through extending the Event class, you’re adding functionality that only needs to be where it’s needed.[/quote]

Again, I was asking about a specific new class. Just as there is MouseEvent, Event, VideoEvent, MetaDataInfoEvent, FlvPlaybackEvent etc, there could be a ObjectEvent.

However, now that you mention metadata, I wonder if the MetaDataInfoEvent, used mainly for cuepoints in videos, may actually allready do what I am saying…

Is having an object floating around with the events a bad thing? Does it mess with the garbage collector? Or is it just unessesary?

Ok… just looked up Documentation, and indeed, fl.video.MetaDataEvent is exactly what I was talking about, and apparently it IS part of the API!!! Heh go figure!

[QUOTE=Daganev;2333632]Ok… just looked up Documentation, and indeed, fl.video.MetaDataEvent is exactly what I was talking about, and apparently it IS part of the API!!! Heh go figure![/QUOTE]

Its a custom API - all fl classes are written in ActionScript and generally relate to custom functionality someone made to work with the Flash Authoring components or something else within Authoring. They are not native to the player.

Most of the other native events are not just Events because they offer something that custom events cannot. For example mouse events determine mouse position or related objects as specified by internal player code. Some of that data would be near to impossible to obtain without those custom events.

livedocs == default :stuck_out_tongue:

[QUOTE=Daganev;2333647]livedocs == default :P[/QUOTE]

:wink:

Just don’t try to use them with Flex