Building a simple flex Module

Source: Internet
Author: User

I 've been playing around with Flex modules lately and thought I 'd post this. it's pretty basic, but it is kind of a "My first module" type experiment. I tried to show a few different things including: calling a module's methods from the parent application as well as setting properties in the parent application from the loaded module.

If you haven't looked at modules in flex yet, I highly encourage you to check out the flex Doc team blog at http://blogs.adobe.com/flexdoc, where you can find their latest version of the "Creating modular applications" chapter (blog entry, PDF ).

<? XML version = "1.0" encoding = "UTF-8" ?>
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" >
< MX: script >
<! [CDATA [
Import MX. Events. videoevent;

[Bindable]
Private var moduletitle: string;

Private var VM: videomodule;

Private function Init (): void {
Vm = videomodule (m1.child );
Moduletitle = VM. getmoduletitle ();
}

Private function stopvideo (): void {
VM. stopvideo ();
}

Private function playpausevideo (): void {
VM. playpausevideo ();
}
]>
</MX: script>

< MX: Panel ID = "Panel" Title = "Module: {moduletitle }" >
< MX: moduleloader URL = "Videomodule.swf" ID = "M1" Ready = "Init ()" />
< MX: controlbar >
< MX: button Label = "Play/pause" Click = "Playpausevideo ()"   />
< MX: button Label = "Stop" Click = "Stopvideo ()"   />
< MX: Spacer Width = "100%"   />
< MX: Label ID = "Playheadtime" Fontweight = "Bold"   />
</ MX: controlbar >
</ MX: Panel >

</MX: Application>

Videomodule. mxml <? XML version = "1.0" encoding = "UTF-8" ?>
< MX: Module Xmlns: MX = "Http://www.adobe.com/2006/mxml" Width = "100%" Height = "100%" >
< MX: script >
<! [CDATA [
Public Function getmoduletitle (): String {
Return "video module ";
}

/* Stop the video playback .*/
Public Function stopvideo (): void {
Videodisplay. Stop ();
}

/* If the video is currently playing, pause playback. Otherwise, Resume playback .*/
Public Function playpausevideo (): void {
If (videodisplay. Playing ){
Videodisplay. Pause ();
} Else {
Videodisplay. Play ();
}
}

Private function updatevideotime (): void {
/* If the playheadtime is 0, the dateformatter returns an empty string.
To work around this we can default the time to 10 ms if the playheadtime
Is zero .*/
VaR ptime: Date = new date (videodisplay. playheadtime * 1000 | 10 );
VaR tTime: Date = new date (videodisplay. totaltime * 1000 );
Parentapplication. playheadtime. Text = dateformatter. Format (ptime) + "/" + dateformatter. Format (tTime );
}
]>
</ MX: script >

<MX: dateformatterID= "Dateformatter"Formatstring= "NN: SS" />

mx: videodisplay id =" videodisplay " source =" http://www.helpexamples.com/flash/video/cuepoints.flv " playheadupdate =" updatevideotime () " />
mx: module >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.