/*
* Copyright 2008-2010 Plura Processing, LP
*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
/*
* This code creates a SWF with 2 buttons: one to start and stop Plura,
* and one to switch the CPU usage of Plura between 50% and 100%.
* It also contains one label, which prints the number of work units that a specified client completed on a specified day.
*/
import com.pluraprocessing.node.affiliate.web.Plura;
import mx.controls.Button;
import mx.controls.Label;
import com.pluraprocessing.node.affiliate.web.PluraEvent;
private var started:Boolean = false;
private var startButton:Button = new Button();
private var changeCPUButton:Button = new Button();
private var plura:Plura;
private var currentCpu:Number = .5;
private var communicationLabel:Label = new Label();
private function init():void {
plura = new Plura("a899fef7-4595-4a8e-9224-9b27ee260fa2", "testClientId", currentCpu); //instantiate Plura object
startButton.label = "Start"; //set up start button
startButton.addEventListener(MouseEvent.CLICK, onClickStartButton);
this.addChild(startButton);
changeCPUButton.label = "Use 100% of CPU"; //set up change cpu button
changeCPUButton.addEventListener(MouseEvent.CLICK, onClickCPUButton);
changeCPUButton.y = 320;
this.addChild(changeCPUButton);
communicationLabel.y = 160; //set up communicationLabel label
this.addChild(communicationLabel);
//check how many work units client '03ee074b-3a4d-4c78-9504-2b8e47880b96' completed on '2008-10-01'
plura.addEventListener(PluraEvent.PLURA_SUCCESS, successListener);
plura.addEventListener(PluraEvent.PLURA_ERROR, errorListener);
plura.getWorkUnitsCompletedByClient("03ee074b-3a4d-4c78-9504-2b8e47880b96", new Date(2008, 10, 1));
}
//if the call to getWorkUnitsCompletedByClient is successful, print the number of work units on the screen
private function successListener(event:PluraEvent):void {
communicationLabel.text = "success! number work units: " + event.result.toString();
}
//if the call to getWorkUnitsCompletedByClient is unsuccessful, print 'error' on the screen
private function errorListener(event:PluraEvent):void {
communicationLabel.text = "error";
}
//on click start/stop Plura button
private function onClickStartButton(event:Event):void {
if (!started) {
started = true;
plura.startPlura(); //start Plura
startButton.label = "Stop";
}
else {
started = false;
plura.stopPlura(); //stop Plura
startButton.label = "Start";
}
}
//on click the change cpu usage button
private function onClickCPUButton(event:Event):void {
if (currentCpu == 1) {
plura.changeCpuUsage(.5); //change Plura's CPU usage to 50%
currentCpu = .5;
changeCPUButton.label = "Use 100% of CPU";
}
else {
plura.changeCpuUsage(1); //change Plura's CPU usage to 100%
currentCpu = 1;
changeCPUButton.label = "Use 50% of CPU";
}
}
//embedded SWF file
[Embed(source="assets/clock1.swf")]
[Bindable]
public var Advertisement:Class;
]]>
</mx:Script>
<!-- embedded swf -->
<mx:Image id="AdvertisementImage" source="{Advertisement}" width="150" height="151.8"/>
</mx:Application>