# Object Events

**URL:** <https://forum.kirupa.com/t/object-events/261670>\
**Category:** flash\
**Created:** [May 29, 2008, 5:50pm UTC](https://forum.kirupa.com/t/object-events/261670 "2008-05-29T17:50:18Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 29, 2008, 5:50pm UTC](https://forum.kirupa.com/t/object-events/261670/1 "2008-05-29T17:50:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 29, 2008, 6:04pm UTC](https://forum.kirupa.com/t/object-events/261670/2 "2008-05-29T18:04:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 29, 2008, 6:19pm UTC](https://forum.kirupa.com/t/object-events/261670/3 "2008-05-29T18:19:03Z")

</div>

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;  
}

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 29, 2008, 7:50pm UTC](https://forum.kirupa.com/t/object-events/261670/4 "2008-05-29T19:50:19Z")

</div>

How do you expect it to work?

---

<div class="post-metadata">

**Author:** ![rbnzdave](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@rbnzdave](https://forum.kirupa.com/u/rbnzdave)\
**Post date:** [May 29, 2008, 9:35pm UTC](https://forum.kirupa.com/t/object-events/261670/5 "2008-05-29T21:35:42Z")

</div>

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

```auto

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

```

---

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 30, 2008, 3:02am UTC](https://forum.kirupa.com/t/object-events/261670/6 "2008-05-30T03:02:23Z")

</div>

> [@senocular;2333213](#):
>
> How do you expect it to work?

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.

---

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 30, 2008, 3:07am UTC](https://forum.kirupa.com/t/object-events/261670/7 "2008-05-30T03:07:49Z")

</div>

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

```auto

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

> **[Model–view–controller](https://en.wikipedia.org/wiki/Model-view-controller)**
>
> Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divides an application into three interconnected parts. This is done to separate internal representations of information from the ways information is presented to, and accepted from the user. The MVC design pattern decouples these major components allowing for efficient code reuse and parallel development. Traditionally used for desktop graphical user interfaces (GUIs), this architect...

and here  
[http://www.cairngormdocs.org/tools/CairngormDiagramExplorer.swf](http://www.cairngormdocs.org/tools/CairngormDiagramExplorer.swf)

---

<div class="post-metadata">

**Author:** ![rbnzdave](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@rbnzdave](https://forum.kirupa.com/u/rbnzdave)\
**Post date:** [May 30, 2008, 3:08am UTC](https://forum.kirupa.com/t/object-events/261670/8 "2008-05-30T03:08:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rbnzdave](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@rbnzdave](https://forum.kirupa.com/u/rbnzdave)\
**Post date:** [May 30, 2008, 3:20am UTC](https://forum.kirupa.com/t/object-events/261670/9 "2008-05-30T03:20:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 30, 2008, 12:46pm UTC](https://forum.kirupa.com/t/object-events/261670/10 "2008-05-30T12:46:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 30, 2008, 3:08pm UTC](https://forum.kirupa.com/t/object-events/261670/11 "2008-05-30T15:08:13Z")

</div>

[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?

---

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 30, 2008, 3:10pm UTC](https://forum.kirupa.com/t/object-events/261670/12 "2008-05-30T15:10:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 30, 2008, 3:16pm UTC](https://forum.kirupa.com/t/object-events/261670/13 "2008-05-30T15:16:35Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![Daganev](https://avatars.discourse-cdn.com/v4/letter/d/fbc32d/32.png) [@Daganev](https://forum.kirupa.com/u/Daganev)\
**Post date:** [May 30, 2008, 3:40pm UTC](https://forum.kirupa.com/t/object-events/261670/14 "2008-05-30T15:40:50Z")

</div>

> [@senocular;2333633](#):
>
> 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.

livedocs == default 😛

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 30, 2008, 3:56pm UTC](https://forum.kirupa.com/t/object-events/261670/15 "2008-05-30T15:56:14Z")

</div>

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

😉

Just don’t try to use them with Flex
