How to ignore a mouse event - actionscript-3

I have a component that is draggable. However, it cannot be dragged if the user drags while the mouse is on the text field. How can I set the Text field so the user can click-drag on that part of the interface?
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" width="210" height="150" styleName="noteStyle" >
<mx:Script>
<![CDATA[
public var testId:int;
public var buttonNumber:int;
public function init():void{
this.addEventListener(MouseEvent.MOUSE_DOWN, makeDraggable)
this.addEventListener(MouseEvent.MOUSE_UP, endDrag)
this.buttonMode = true;
this.useHandCursor = true;
}
public function saveButtonHandler():void{
dispatchEvent(new Event ( "noteClosed"));
}
public function cancelButtonHandler():void{
dispatchEvent(new Event ( "noteCancelled"));
}
public function makeDraggable(e:Event):void{
//If the target and the current target are the same, then it must be the background, so make it draggable.
//Stops the text field and buttons from being draggable
trace("Target= "+e.currentTarget+" "+e.target)
if(e.currentTarget==e.target){
this.startDrag();
}
}
public function endDrag(e:Event):void{
this.stopDrag();
}
]]>
</mx:Script>
<mx:Text text="Add a note: Drag to move" styleName="myriadPro14" selectable="false" />
<mx:Button id="saveButton" label="Save" x="146" y="120" click="saveButtonHandler()" />
<mx:Button id="cancelButton" label="Cancel" x="10" y="120" click="cancelButtonHandler()" />
<mx:TextArea id="noteText" width="200" height="80" horizontalCenter="0" verticalCenter="-12"/>
</mx:Canvas>

Add an event listener to the text field as well.

Related

How to disable a component inside Datagrid which is rendered using inline item renderer

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var myTimer:Timer;
[Bindable] public var isEnabled:Boolean = true;
public function getDetails():void {
Alert.show("Got it!!");
isEnabled = false;
myTimer = new Timer(5000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();
}
public function timerHandler(event:TimerEvent):void {
isEnabled = true;
}
]]>
</mx:Script>
<mx:ArrayCollection id="myAc">
<mx:source>
<mx:Object version="1.0" telephone="9875454214" />
<mx:Object version="2.0" telephone="8794568784" />
<mx:Object version="3.0" telephone="8796454487" />
</mx:source>
</mx:ArrayCollection>
<mx:HBox>
<mx:DataGrid verticalScrollPolicy="on" focusEnabled="false" name="Version" id="Version" width="100%" height="65" dataProvider="{myAc}" >
<mx:columns >
<mx:DataGridColumn width="150" dataField="version" headerText="Version" />
<mx:DataGridColumn width="70" dataField="telephone" headerText="Telephone" />
<mx:DataGridColumn width="90" paddingLeft="20" headerText="Download">
<mx:itemRenderer>
<mx:Component>
<mx:Image height="10%" source="css/page_excel.png" click = "outerDocument.getDetails()" enabled = "{outerDocument.isEnabled}" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:HBox>
</mx:Application>
This application is programmed to disable the Image when it is clicked and Enable the same after 5 sec. But it is disabling whole Column. I want it to disable only the clicked Image.
Change your mxml
<!--<mx:Image height="10%" source="css/page_excel.png" click = "outerDocument.getDetails()" enabled = "{outerDocument.isEnabled}" />-->
<mx:Image height="10%" source="css/page_excel.png" click = "outerDocument.getDetails(event)" />
And here is the AS code.
public function getDetails(event: MouseEvent):void {
Alert.show("Got it!!");
//isEnabled = false;
event.target.enabled = false; // Disable clicked Object.
myTimer = new Timer(5000, 1);
//myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, nextfuncWithParams(timerHandler, event.target)); // Pass clicked object.
myTimer.start();
}
public function nextfuncWithParams(nextfunc: Function, params: Object): Function {
return function(event:TimerEvent): void{
nextfunc(event, params);
}
}
public function timerHandler(event: TimerEvent, MouseEventTarget: Object):void {
//isEnabled = true;
MouseEventTarget.enabled = true; // Enable passed object.
}
Working Example: http://wonderfl.net/c/Gv9k
Update
For using Image.
public function getDetails(event: MouseEvent):void {
//Alert.show("Got it!!");
//event.target.enabled = false; // event.target was Loader...
var obj: Object = event.target;
while (obj.parent)
{
if (obj is Image)
{
Image(obj).enabled = false;
break;
}
obj = obj.parent;
}
myTimer = new Timer(5000, 1);
//myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, nextfuncWithParams(timerHandler, obj));
myTimer.start();
}

How can I stop audio from playing from a video file?

This code plays Youtube videos. The file works using Debug or Run buttons in FlashBuilder but has a bug when played from a web server or from the Export Release folder: when the second video runs the audio from the first video keeps playing. How can I unload the first audio?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private var swfLoader:SWFLoader;
[Bindable] public var videoToPlay:String
public function playVideo(videoNum:int):void
{
if(swfLoader)
{
swfLoader.autoLoad = false;
swfLoader.unloadAndStop();
hg.removeChild(swfLoader);
SoundMixer.stopAll();
}
var videoAddress:String
if(videoNum == 1){
videoAddress = "m2dg6teC7fg";
}else{
videoAddress = "0QRO3gKj3qw";
}
videoToPlay = "https://www.youtube.com/v/VIDEO_ID?v=" + videoAddress;
play();
}
public function play():void
{
swfLoader = new SWFLoader();
swfLoader.y = 100;
swfLoader.load(videoToPlay);
hg.addChild(swfLoader);
}
]]>
</mx:Script>
<mx:HBox id="hg">
<mx:Button id="button1" y="50" label="Button1" click="playVideo(1)" useHandCursor="true" buttonMode="true" />
<mx:Button id="button2" y="50" label="Button2" click="playVideo(2)" useHandCursor="true" buttonMode="true" />
</mx:HBox>
</mx:Application>
The solution to stop first video/audio on second button click is:
Use following in your code to unload first video from swfloader:
<fx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private var swfLoader:SWFLoader;
[Bindable] public var videoToPlay:String
public function playVideo(videoNum:int):void
{
if(swfLoader)
{
swfLoader.autoLoad = false;
swfLoader.unloadAndStop();
// swfLoader.autoLoad = true;
hg.removeElement(swfLoader);
SoundMixer.stopAll();
}
var videoAddress:String
if(videoNum == 1){
videoAddress = "m2dg6teC7fg";
}else{
videoAddress = "0QRO3gKj3qw";
}
videoToPlay = "https://www.youtube.com/v/VIDEO_ID?v=" + videoAddress;
play();
}
public function play():void
{
swfLoader = new SWFLoader();
swfLoader.y = 100;
swfLoader.load(videoToPlay);
hg.addElement(swfLoader);
}
]]>
</fx:Script>
<s:HGroup id="hg">
<s:Button id="button1" y="50" label="Button1" click="playVideo(1)" useHandCursor="true" buttonMode="true" />
<s:Button id="button2" y="50" label="Button2" click="playVideo(2)" useHandCursor="true" buttonMode="true" />
</s:HGroup>
I have edited code below, which works for your problem(I tested it my side). Try it and let me know it's works?
Edit:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private var swfLoader:SWFLoader;
[Bindable] public var videoToPlay:String
public function playVideo(videoNum:int):void
{
if(swfLoader)
{
swfLoader.source = "";
swfLoader.load(null);
SoundMixer.stopAll();
}
var videoAddress:String
if(videoNum == 1){
videoAddress = "m2dg6teC7fg";
}else{
videoAddress = "0QRO3gKj3qw";
}
videoToPlay = "https://www.youtube.com/v/VIDEO_ID?v=" + videoAddress;
play();
}
public function play():void
{
swfLoader = new SWFLoader();
swfLoader.y = 100;
swfLoader.load(videoToPlay);
hg.addChild(swfLoader);
}
private function onRemove():void
{
}
]]>
</mx:Script>
<mx:HBox id="hg">
<mx:Button id="button1" y="50" label="Button1" click="playVideo(1)" useHandCursor="true" buttonMode="true" />
<mx:Button id="button2" y="50" label="Button2" click="playVideo(2)" useHandCursor="true" buttonMode="true" />
</mx:HBox>
</mx:Application>

OK button in a dialog popup not working in flex

I am new to learning flex and I have this application which opens up a popup displays some checkbox values and the once the user clicks the OK button populates an array and then closes. But in my code, when I click the OK button nothing happens.
private function closeDialog(event : CloseEvent) : void {
PopUpManager.removePopUp(this); // close this dialog
}
private function onClickOK (event : CloseEvent) : void {
var values:ArrayCollection = new ArrayCollection();
for (i = 0; i < table.length; i++) {
var row:Array = table.getItemAt(i);
if (row["selected"]) {
var valueRow:Array = new Array();
arrayRow["colA"] = row["colA"];
values.addItem(valueRow);
}
}
page.model["choosenvalues"] = values;
closeDialog(event);
}
And here is the flex code
<mx:VBox paddingLeft="10" paddingRight="10">
<mx:HBox width="100%" height="100%">
<mx:Spacer width="2%" />
<mp:Table id="selectTable" dataProvider="{table}" title="" height="350">
<mp:columns>
<mx:AdvancedDataGridColumn dataField="selected" headerText=" " editable="true" textAlign="center" minWidth="36" width="36" paddingLeft="0" paddingRight="0">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox width="18" click="{data.selected = !data.selected}" label="" paddingLeft="0" paddingRight="0"/>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn headerText="Column A" minWidth="240" dataField="colA"/>
</mp:columns>
</mp:Table>
</mx:HBox>
<mx:HBox width="100%">
<mx:Spacer width="85%" />
<mx:Button label="OK" click="onClickOK(null)" enabled="true"/>
<mx:Button label="Cancel" click="closeDialog(null)"/>
</mx:HBox>
</mx:VBox>
Try removing the event parameters from methods, since you don't use them. Anyway, the onclick handler should accept MouseEvent or just Event, not CloseEvent.
private function closeDialog() : void {
PopUpManager.removePopUp(this); // close this dialog
}
private function onClickOK () : void {
...
closeDialog();
}
MXML:
<mx:Button label="OK" click="onClickOK()" enabled="true"/>
<mx:Button label="Cancel" click="closeDialog()"/>
Note: parameterless event handlers are possible with MXML, since if you try it with AS, you'll get warnings.

Show snapshots from camera Flex

I created a flex application that snapshot a picture of the webcam. Im trying now to save every snapshop and display it directly when the image has been capture. But I cant seems to understand how to.
I want the images to be display in the Thumbnail box.
Any help ? or any sites I can found some help on ?
This is what I have for the moment
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top"
horizontalAlign="center" paddingTop="0" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.UIComponent;
private function videoDisplay_creationComplete() : void
{
var camera:Camera = Camera.getCamera();
if (camera)
{
videoDisplay.attachCamera(camera);
}
else
{
Alert.show("Oops, we can't find your camera.");
}
}
private function capture_click() : void
{
var snap:BitmapData = new BitmapData(320, 240, true);
var snapBmp:Bitmap = new Bitmap(snap);
snapBmp.width = 320;
snapBmp.height = 240;
if(snapshotHolder.numChildren > 0)
snapshotHolder.removeChildAt(0);
snapshotHolder.addChild(snapBmp);
snap.draw(videoDisplay);
}
]]>
</mx:Script>
<mx:HBox>
<mx:Panel title="Video">
<mx:VideoDisplay id="videoDisplay" creationComplete="videoDisplay_creationComplete();" width="320" height="240" />
</mx:Panel>
<mx:Panel title="Snapshot">
<mx:UIComponent id="snapshotHolder" width="320" height="240" />
</mx:Panel>
</mx:HBox>
<mx:HBox>
<mx:Button label="reload camera" click="videoDisplay_creationComplete();"/>
<mx:Button label="capture" click="capture_click();"/>
</mx:HBox>
<mx:HBox>
<mx:Panel title="Thumbnails">
<mx:UIComponent id="snapshotHolderTN" width="128" height="96" />
</mx:Panel>
</mx:HBox>
</mx:Application>
Pls try with this when u click for image snaps.
var bmp:BitmapData = new BitmapData(videodisplay.width,videodisplay.height);
bmp.draw(drawArea);
var jpgEncode:JPEGEncoder = new JPEGEncoder(50);
var imageByte:ByteArray = jpgEncode.encode(bmp);
var fileRef:FileReference = new FileReference;
fileRef.save(imageByte);

Flex 3: inquiry about printing

I have created a scheduling application that spans upwards of 16 weeks. I would like to be able to print the schedule using Flex. I've created a test application that lists incrementing dates. These dates obviously stretch longer than the width of my computer. I would like for my print function to print the entire width of dates across several pages... currently, it prints just what appears on my screen. Is there a way to accomplish this?
Below is the app i've created. There are some calls to custom functions, but they in no way relate to the issue at hand:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
<mx:Script source="functions/dateFunctions.as" />
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
[Bindable] public var date:Date = new Date;
public var numDays:Number = 50;
[Bindable] public var datesAC:ArrayCollection = new ArrayCollection;
public function init():void
{
var tempDate:String = new String;
for (var i:int = 0; i < numDays; i++)
{
tempDate = dateToNumText(rightDate(date.getMonth(), date.getDate() + i, date.getFullYear()));
datesAC.addItem(tempDate);
}
}
private function printMe() :void
{
var pj:PrintJob = new PrintJob();
pj.start();
// setTimeout(function() :void { finishPrinting(pj);}, 1);
finishPrinting(pj);
}
private function finishPrinting(pj:PrintJob): void {
pj.addPage(this);
pj.send();
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:Button id="print" label="Start Print" click="printMe()" />
<mx:HorizontalList id="dateList" dataProvider="{datesAC}" width="100%" height="100%" useRollOver="false">
<mx:itemRenderer>
<mx:Component>
<mx:Canvas borderColor="#000000" borderSides="right" borderStyle="solid">
<mx:Text text="{data}" textAlign="center" color="#000000" width="100" />
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:HorizontalList>
</mx:VBox>
</mx:Application>
You would have to break up/paginate content on your own. You can send each such logically broken up page to PrintJob.appPage() API so it becomes a printed paper. At present, what is happening would be that content would be getting clipped.
I guess you should use PrintJob.addPage() to add your dates to print job.