6 Replies Latest reply on Oct 13, 2009 1:44 PM by WordRad

    detecting visual content change

    WordRad Level 1

      This could be a very basic question, I don't know.

      What event would signal that the visual content of an SWFLoader had changed or how would you detect that.


      Actually if the visual content changes there is in fact a "render" event broadcast in the parent application, but I don't know how to determine which SWFLoader caused it.


      Say you have one SWFLoader on a page that contains some sort of input control but its just sitting there doing nothing until a user presses something on it, and then there is a render event in the parent application. However, if there is another SWFLoader that contains a continually playing VideoDisplay, then there will be continal render messages being broadcast in the parent application (I verified this.) My point being that the parent application is getting signaled somehow the instant the visual content of some embedded SWFLoader changes. But the question is how does my code determine specifically which SWFLoader changed.
        • 1. Re: detecting visual content change
          Yozef0 Level 1

          I'm not sure I get 100% the question... I took a quick look at the Event dispatchers for the SWFLoader, dosen't seem to have a Change (unless you mean the change happens in the child swf, the one being loaded)... Also try (pretty generalized)


          theSwfLoader.addEventListener(Event.CHANGE, traceMe);


          funtion traceMe (e:Event) {

               trace (e.currentTarget);



          or even better I saw at Adobe Max someone mention describeType(e.currentTarget) ... gives out much more info in XML that gets traced.

          • 2. Re: detecting visual content change
            WordRad Level 1

            Joseph, just to clarify my original question,  I have a bunch of swloaders on a canvas.  If one of them changes state visually I want to know which one and at the time it happens.  And what I mean by "changing state visually' is merely what it says - the object's visual appearance changes in some way shape or form -  a button is pressed, a video display advances a frame, whatever.  And as to the reasonableness of expecting this is possible in flex, I pointed out that I verified that "render" broadcast events were being triggered by any visual change occuring in any SWFLoader (and you're correct that what I have in mind is the actual SWF that's running in it, as an SWFLoader itself  does not have any visible interface itself.)


            But the problem with listening to render is that it doesn't tell me which SWFLoader actually changed, not in the target or current target.  I just know that render events are being triggered the instant some SWFLoader changes visually.  (Apparently render events come from the stage and in response to someone calling stage.Invalidate().  So maybe there's not a record of who called stage.invalidate, I don't know.)


            Now as to your suggestions:


            I looked up the Change event and correct me if I'm wrong but that is not something utilized at a high level.  For example a TextArea and Button I believe have "Change" in their list of events but they did not inherit this from anything, and sprite, displayobject, interactiveobject etc do not utilize the change event.   But anyway I just tried it  _appLoaded.addEventListener("change",handler) (where appLoaded is the actual application for the loaded .SWF) and nothing.   _appLoaded.addEventListener("render",handler)  does fire, but in response to render events caused by any other loaded SWF being invalidated (not just _apploaded).


            As far as "describeType(e.currentTarget) ." I'll do a text search on that, but perhaps you could elaborate more on how you think it could solve my problem.





            • 3. Re: detecting visual content change
              WordRad Level 1

              Actually what I think I need to do is override somehow some of the public or protected methods of the loaded SWF's application, (for example updateDisplayList()) but I don't know how to do this.  I'm thinking if there were a way to override (not in the sense of class definitions but rather reassigning the function somehow) updateDisplayList for example, I could monitor when it was being called in the application.


              That's kind of hazy, but were I'm headed right now, if I can just figure out how to redirect a function (even a protected one hopefully) from the loaded SWF's application.

              • 4. Re: detecting visual content change
                Gregory Lafrance Level 6

                SWFLoader has the click event, and that event will tell you what SWFLoader was clicked.


                If you need more finely grained control, for example if your loaded SWFs are other Flex apps, are you might need to establish communication between them and the main app.


                Custom events may be an option and are likely the best practice for such communication.


                If this post answers your question or helps, please mark it as such.

                • 5. Re: detecting visual content change
                  WordRad Level 1

                  Greg Lafrance:


                  Thanks for the reply:


                  Just for the record I have never said anything about needing to detect click events.


                  Once again, I have a bunch of SWFLoader on a canvas.  If one of them changes visibly in anyway (be it animation, user interaction - OK maybe that's where you saw the relevance of click events, etc.) I want to know which one changed.  And just to reiterate, it seems something in the flex process knows the instant one of them changes visually, because a render event is triggered when that happens.  However, the render event doesn't tell me which one of them changed.


                  OK, I'll spell it out more why I need to know this.  I have  a custom graphical modicification I''m making to every SWFLoader. (And yes I mean the actual loaded content.)  If that SWFLoader is just an image (JPG PNG etc) that modification just needs to be made once, when it is first loaded (where basically I manipulate the BitmapData.)  However, if the SWFLoader is a loaded application (an SWF)  then that modification needs to be be made every time it changes visually.  As you can see, this is an expensive operation, so I only want to modify the SWF that's actually changed, not all of them.


                  As far as using custom events, that did cross my mind at one point, but I've never used them,  if you can elaborate on how that would solve my problem that would be great.




                  • 6. Re: detecting visual content change
                    WordRad Level 1

                    One other thing: inludeInLayout is turned off for these SWFLoaders, so don't know if that's a problem.  (With it on though, there's interference with  various things I'm doing.)