|
AccessingCaptivateEvents
Article on how to access and monitor Captivate Slide and Movie events.
IntroductionOn top of offering additional widget events, CpGears allows you to monitor the standard Captivate events as well. This article will show you how. ProjectA FlashDevelop? project containing all the files for this article is available in the Download Section under the name EventWidgetProject. Monitoring Captivate EventsCaptivate dispatches different events during a presentation. Some of the events are targeting the movie state (starting/pausing/resuming/stopping) while other events are related to entering/leaving a slide and when a question/interaction item has been submitted. These events are:
To monitor them from CpGears, just add an event listener from any view. Typically, from the initialize() method, you would type:
import com.adobe.captivate.events.CPSlideEnterEvent;
override public function initialize():void {
movie.addEventListener(CPSlideEnterEvent.CPSLIDEENTEREVENT, onEnterSlide);
}
private function onEnterSlide(event:CPSlideEnterEvent) {
<YOUR CODE HERE>
}
Linking with the Captivate EventsIn order to compile the code containing Captivate Events, you need to point Flash to the folder containing these event classes. You can find them under your Captivate installation folder in .\ActionScript\export\as3\com\adobe\captivate\events Or you can also use the Captivate.swc component that is the download section and that contains all the Captivate Events. |
Hi Whyves,
Just a quick question prompted by the information you've provided above. Is it possible to pause the Captivate timeline while the widget does its stuff and resume again once the widget has completed its task? (CPMoviePauseEvent?)
If so, how would you call those functions?
Thanks for your help. Your work on CPgears is most appreciated! :-)
Jon
Hi Jon,
You would pause and resume the movie through the system variables "rdcmndPause" and "rdcmndResume". I should extend the API to offer a "play()" and "pause()" method but for the moment you can do "movie.setCpVariable("rdcmndPause", 1);" from one of the view.
Marvellous - thanks very much Whyves. :-)
Hi Jon,
You should get the new version of CpGears? (v1.1). I have added a movie control API to allow you to play/pause/exit/gotoNextSlide/gotoPreviousSlide. Thanks for proposing it!
Oh yeah, to access it, just type:
I just popped back to the CPgears project site as I finally have a day to sit down and work out this stuff and saw your replies above - sorry I didn't check back sooner!
Thanks Yves - you're a star! :)
Hi Whyves,
Your CpGears? framework is awesome! I used it to create a widget in AS3 for Captivate 5. It works perfectly. The widget I created allows you to enter in a copyright date, title and subtitle. You can also use a dropdown menu to select one of four colors. You can select normal, small, or large for the title and subtitle appearance. You can also use a checkbox to make the subtitle appear smaller than the title. All of this works beautifully. Once published the widget compiles everything and loads an external flash file depending on which color you chose. The loading of the external flash files made it hard to see the end result display correctly on the Captivate stage... but with some creative coding I was able to get that working too.
There is one question I have... This widget controls the look and feel and template of a course. So far it only controls the start of the course. I would like to have an embedded Flash file on the last slide of the course. The slide number of this last slide would vary based on the course length. I would like the Flash file to automatically know what color was chosen in the widget on first slide. Then the Flash file would load the correct ending template. I don't know how to make the flash file on the last slide communicate with the widget on the first. I tried setting a Captivate variable and having the widget change it... then having the Flash file read from it. I just can't get the linkage right. In CpGears?... how can you access custom user variables created in Captivate? Also.... is there a way to access and modify some of the variables created by the widget from an SWF file embedded elsewhere in Captivate?
In Captivate 4 using AS 2 based widgets I was able to access custom Captivate user variables by accessing "root.variableName" or "this.parent.parent.parent.variableName". What is the correct path for Captivate 5 with AS 3? Even better... is there a path I could use in an SWF to modify the data in variables created by the CpGears? widget?
Any help you could give me would be greatly appreciated.
Thanks for all your hard work!
Jon
Hi Jon,
In CpGears?, you can access and set Captivate variables from movie.setCpVariable() and movie.getCpVariable(). At the end of the day, it's the same mechanism than in AS2. The variables are stored on the CaptivateMainTimeline?.
What I may suggest to you is to use cpSetVariable() from the widget and root.parent.root.cpGetValue(variableName) from your embedded flash file. Give this a try and let me know if this works out for you.
Whyves
Hi Yves!
Thanks for the reply, but it wasn't a question I asked!
There's clear two or more of us 'Jon's trying to confuse you!
;-)
Jon (nockieboy)
for Captivate 5. It works perfectly. The widget I created allows you to enter in a copyright date, title and subtitle. You can also use a dropdown menu to select one of four colors. You can select normal, small, or large for the title and subtitle appearance. You can also use a checkbox to make the subtitle appear smaller than the title. All of this works beautifully.
file depending on which color you chose. The loading of the external flash files made it hard to see the end result display correctly on the Captivate stage... but with some creative coding I was able to get that working too.template of a course. So far it only controls the start of the course. I would like to have an embedded Flash file on the last slide of the course.
the widget on first slide. Then the Flash file would load the correct ending template. I don't know how to make the flash file on the last slide communicate with the widget on the first. I tried setting a Captivate variable and having the widget change it... then having the Flash file read from it. I just can't get the linkage right. In CpGears?... how can you access custom user variables created in Captivate? Also.... is there a way to access and modify some of the variables created by the widget from an SWF file embedded elsewhere in Captivate?Captivate user variables by accessing "root.variableName" or "this.parent.parent.parent.variableName". What is the correct path for Captivate 5 with AS 3? Even better... is there a path I could use in an SWF to modify the data in variables created by the CpGears? widget?
Hi Yves,
Yep... I am a different Jon... however... both of us spell our names the right way! Haha.
Thanks for your solution. I was able to modify a Captivate user variable once the widget was run. I was then able to access that variable from a Flash file on a different slide. The only bummer is that in order to use my widget... a person has to create the variable in Captivate and make sure it is named correctly. Is there any way to have the widget create the Captivate variable on the fly once the widget is imported and edited? Or... is there any way to access the widget variables from another Flash file without running the data through a Captivate user variable?
Thanks for all your help!
Jon (CodeMonkey?)
Hi CodeMonkey? Jon,
That's an unfortunate side effect that you need to create the variable in Captivate. However, this is only required if you want to use the variable inside Captivate. If you don't need to access it from inside Captivate, then just access the CaptivateMainTimeline? movieclip and just add a variable there. This is a dynamic movieclip so you can add variable on the fly and retrieve it from your flash movie.
So, from inside CpGears? do something like: movie.handle["MyVariable?"] and from the flash file: root.parent.root["MyVariable?"]
HTH
Yves
Hey Yves,
Seems my e-mail has been confusing me - don't know if you got my original question, so I'll re-post it here.
Is there any way I can insert the code/class for pausing/restarting the Captivate timeline into a straight (non-widget) Flash animation?
I've got a couple of Flash animations that are interactive and would really benefit from being able to pause the Captivate timeline until they're completed, but I've having the devil's own job of converting these complicated animations into a single 'Runtime' movieclip to use in the static widget project.
I'm hoping there's a way to link the CpGears? class to the standalone Flash animation where I can call the pause/play functions for the Captivate timeline without having to use a full widget class?
Can it be done?
Jon (not CodeMonkey?) ;-)
Hi Jon (nockie),
I have sent you an e-mail a week ago. Did you get it? I sent in on April 6th. In case you did not get it, here's an extract:
You can get access to the captivatemaintimeline and set variables from there. E.g.:
CaptivateMainTimeline?.cpEISetValue("rdcmndPause", 1) to pause the movie and
CaptivateMainTimeline?.cpEISetValue("rdcmndResume", 1) to resume it.
At the end of the day, the CpGears? framework just exposes these mechanism in a simpler and more effective way. You could always scan the CpGears? code on GoogleCode? to learn how it was done. In case you're not sure how to access the main timeline, just do "root.parent.root" from your flash file.
Yves
Yves,
Ah! Overlooked it in its simplicity (and other such excuses for me being dumb!) ;-)
No, didn't get an e-mail, but my e-mail has been acting up recently and spamming things that shouldn't be, etc, so I'll chalk that mail up to the great e-mail Bermuda Triangle.
Thanks again,
Jon
Hey Yves,
Do you know what event fires when the status flag for self paced learning is set? I'm looking to hook into the event to unlock the slide when the whole slide has been viewed.. unfortunately CPSlideExitEvent fires when the user leaves the slide (no matter which method they leave) and can't be used for my purposes.
Any help will be greatly appreciated!
Thanks!
Linda