27 Responses to Top 5 of WidgetFactory 5 – #3 Captivate 5 Events

  1. jjl says:

    This is another great tutorial. Was wondering if you had a quick way of detecting if a slide is a captivate question.

    • Tristan says:

      if (cpVariables.cpInfoCurrentSlideType == “QuestionSlide”) will tell you if the current slide being viewed is a question slide.

      If you want to make sure that the slide the widget is on is a question slide, try: if (widgetSlide.toString() == “[object rdQSlide]“)

  2. jjl says:

    any ideas on how you would get an array of each slides SlideType

  3. jjl says:

    the reason I ask is ive developed a captivate loader and am trying to deactivate my pagination when the captivate is a question slide to wait for the answer and I figure out the way to get the array and thanks heaps by the way. but im still having trouble getting a listener to my embedded captivate files.

    eg
    if(topic[num] == “[object rdQSlide]“){
    currenttopic.addEventListener(QuestionWidgetEvent.QUESTION_SUBMITTED, onQuestionSubmit);
    }

    ps: class deffinition error if you dont use QuestionWidgetEvent for your example above

    • Tristan says:

      Okay, well you can get an array of slides like so:

      var slidesArray:Array = new Array();

      for (var i:int = 0; i <= widgetSlide.parent.numChildren – 1; i++) // Loop through parent's children
      {

      if (widgetSlide.parent.getChildAt(i).hasOwnProperty("isSlideActive")) // If the current child has the property we're looking for
      slidesArray.push(widgetslide.parent.getChildAt(i)); // Add it to the array

      }

      Also, you add the QuestionWidgetEvent.QUESTION_SUBMITTED event listener to the widget itself, not the slide.

      • jjl says:

        Sorry Im probably realy anoying was wondering if you could give me a hand I dont think I have explained my self well.

        have you played much with listening for quiz events on loaded CP files.

        Ive made a preloading widget with my own pagination. my pagination detects when it is a question slide and deactivates. but I cant figure out how to listen for completion of a question so I can reinable my pagination and move to the next slide.

        any help with this would be greatly appreciated.

  4. jjl says:

    well thats the thing because I have embedded the captivate file it doesnt contain a widget and only the parent file can access the widget events.

    • Tristan says:

      I’m afraid I don’t quite understand you. Are you writing this code in a widget, or a normal swf that’s being imported into Captivate as an animation?

      • jjl says:

        in a widget I use the dialogue properties to select a captivate file then in runtime I load it then if its has a quiz slide i need to listen for the submition of this question and call a function to update my pagination.

        • Tristan says:

          Is this in an aggregated project? I don’t quite understand what you mean by ‘selecting a Captivate File’.

          Anyway. Just to make sure. You’ve added the QuestionWidgetEvent.QUESTION_SUBMITTED listener to the widget, not the slide right?

          • jjl says:

            mm it doesnt seem to work

            public function loadTopic():void {
            l.contentLoaderInfo.addEventListener(Event.COMPLETE, populateCanvas);
            l.load(new URLRequest(properties.fileRefference));
            }

            public function populateCanvas(event:Event):void {
            canvas.addChild(l);
            canvas.addEventListener(QuestionWidgetEvent.QUESTION_SUBMITTED, questSub);
            }
            public function questSub(event:QuestionWidgetEvent):void {
            //do stuff
            }

  5. Tristan says:

    So I take it that the Canvas is the widget, and this code is in another swf that’s put into Captivate as an animation, is that right?

  6. jjl says:

    The canvas is a empty movie clip that exist in the widget and the other swf is a captivate swf containing a quiz

  7. Tristan says:

    And you’re trying to listen for the quiz completing in the Captivate Movie you’re loading in. So this is one of those Captivate inside of Captivate things.

    Ah, I see…

    The widget will only pick up events from quizzes inside its Captivate Movie. I recommend sticking another widget in the loaded Captivate Movie which listens for the QuestionWidgetEvent.QUESTION_SUBMITTED event, and responds to it by dispatching another custom event that uses bubbles. Then the top widget can listen for the custom event. Something like this:

    Sub-Widget:

    addEventListener(QuestionWidgetEvent.QUESTION_SUBMITTED, onQuestionSubmitted);

    private function onQuestionSubmitted(e:QuestionWidgetEvent):void
    {
    dispatchEvent(new Event(“customEventName”, true, false));
    }

    In the top widget:

    addEventListener(“customEventName”, onCustomEvent);

    // Function will run as if it was responding to the question submitted.
    private function onCustomEvent(e:Event):void
    {
    // Do stuff
    }

  8. jjl says:

    Thanks heaps tristan your a saviour

    only one little problem it triggers twice

  9. jjl says:

    fixed it awsome hey most greatly apprecitly

  10. jjl says:

    hey Ive come accross a new issue that my question widgets don’t apear onRuntime the first time I view the slide I navigate out and navigate back then they appear

  11. Tristan says:

    Hi JJL,

    Sorry I haven’t replied so far. I’ve been a bit flooded the past couple of days.

    Is this the same widget we were talking about above?

    What type of widget is it? (Static, Interactive, Question)

    What are you trying to show?

    Have you tried bringing it into a blank movie and seeing if it works there?

    • jjl says:

      hey tristan,

      ahh dont worry about that buddy just glad you can help when you can I realy appreciate your time and understand how buisy you must be.

      Well Im currently developing a series of question widgets. they sit in a captivate file that im loading into my interactive widget that is a loader that yourself and Wyevs have been helping me with. it sits in a captivate file and loads other captivate files.

      now the first time I load it the question widget doesnt enterRuntime if I go out and reload it it works fine.

      Now ive come up with a work around by just making all the functionality work in its basic form without entering runtime but the triggerSubmitProcess() doesnt seem to trigger on my first instance.

      any ideas??

      and what would be preventing your enterRuntime function from being called in my loader.

      • Tristan says:

        Sorry jjl. Not many ideas.

        The only thing I can think of is if you’ve unticked the visibility for the widget in Captivate. Currently that stops enterRuntime from triggering (for the moment, working on it :D )

        Without seeing your project or code, I can’t really tell what’s going on.

  12. Nicholas says:

    so if i had a widget that was part of a captivate master slide for all slides, how do i attach a ENTER_SLIDE or EXIT_SLIDE event that wouldn’t fire off for every slide when i enter/exit just one slide?

    in other words, if my master slide is used 8 times, and i enter/exit slide 1, i get 8 events fired instead of just the one. the only workaround i have is to put in a condition to check that the widgetSlide is the currentSlide – i am just hoping for smthg more elegant …

    • Tristan says:

      I’m afraid that’s not the way master slides work.

      When the Captivate Movie is published, objects on the master slide are copied to the slides that point to them. So instead of having one widget appearing and disappearing over eight slides, You’ll have eight widgets, one placed on each sllide.

      So you need to treat that circumstance as if the user pasted the widget on to the slide and set it to appear till End of Slide.

  13. Dave says:

    I built an interface widget that in Captivate the timing is set for the Entire Project. This supposedly sets the widget to the top most layer. Unfortunately, the Captivate-generated Table of Contents is above the widget. Is there any way to get the TOC behind the widget?

    • Tristan says:

      Hi Dave,

      The reason why this isn’t happening is that the slide container (which the widget is inside) appears bellow the TOC. So no matter how high inside the slide your interface appears, the TOC will always be in front. Probably the best way to get around this is rather than adding the interface as a child to the widget, add it as a child to the ‘captivateMainTimeline’ property. This is the same container that holds the TOC, so your interface can appear in front of it. Just make sure to remove your interface from captivateMainTimeline in the exitRuntime() template method.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>