I am trying to place 5 cards overlapping 30% on one another. and trying to give a movement to it using mouse events . It should drop within the 5 cards only, not outside of that.
I have learned the drag and drop events and executed it, but i cannot place the card within the 5 cards .
Please somebody help me in this. Please Check the Below Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="carcan();">
<mx:Script>
<![CDATA[
import mx.containers.Canvas;
import mx.controls.Image;
private var images:Array;
private var images1:Array;
private const IMAGE_COUNT:uint = 5;
private var img:Image;
private var img1:Image;
private var points:flash.geom.Point;
private var offset_x:int;
private var offset_y:int;
private var canal:Canvas;
private var doDrag:Boolean;
[Embed(source='cards/2C.png')]
private var Image0:Class;
[Embed(source='cards/2D.png')]
private var Image1:Class;
[Embed(source='cards/2H.png')]
private var Image2:Class;
[Embed(source='cards/2S.png')]
private var Image3:Class;
[Embed(source='cards/3C.png')]
private var Image4:Class;
public function carcan():void
{
canal = new Canvas();
canal.setStyle("backgroundColor","blue");
canal.x=100;
canal.y=50;
canal.width=500;
canal.height=400;
this.addChild(canal);
init();
}
public function init():void
{
images = new Array(IMAGE_COUNT);
for (var i:int = 0; i < IMAGE_COUNT; i++)
{
img= new Image();
img1= new Image();
images[i] = this["Image" + i];
trace(images[i]);
img.x=(i*30)+50;
img.source=images[i];
img.id="Image"+i;
canal.addChild(img);
img.addEventListener(MouseEvent.MOUSE_DOWN, md);
img.addEventListener(MouseEvent.MOUSE_MOVE, mm);
canal.addEventListener(MouseEvent.MOUSE_OUT,smu);
img.addEventListener(MouseEvent.MOUSE_UP, mu);
}
}
public function smu(event:MouseEvent):void
{
img.alpha=1;
img.stopDrag();
doDrag=false;
setCards();
}
public function mo(event:MouseEvent):void
{
if(doDrag==true)
{
img.addEventListener(MouseEvent.MOUSE_DOWN, md);
img.addEventListener(MouseEvent.MOUSE_UP, mu);
img.stopDrag();
img.alpha=1;
img.removeEventListener(MouseEvent.MOUSE_MOVE, mm);
}
else
{
img.addEventListener(MouseEvent.MOUSE_MOVE, mm);
}
}
public function md(event:MouseEvent):void
{
img = new Image();
doDrag=true;
canal.setChildIndex(Image(event.target),images.length-1);
img.addEventListener(MouseEvent.MOUSE_MOVE, mm);
}
public function mm(event:MouseEvent):void
{
if(doDrag==true)
{
points = new Point();
images = new Array(IMAGE_COUNT);
img = new Image();
img = Image(event.target);
points.x=event.target.x;
points.y=event.target.y;
points = localToGlobal(points);
img.x=points.x;
img.y=points.y;
img.alpha=0.7;
img.addEventListener(MouseEvent.MOUSE_UP, mu);
var boundar:flash.geom.Rectangle = new Rectangle(this.x, this.y, 250, 100);
}
}
public function mu(event:MouseEvent):void
{
img.alpha=1;
canal.stopDrag();
doDrag=false;
canal.stopDrag();
doDrag=false;
var current:Image = event.currentTarget as Image;
var num1:int = current.x;
if(num1 < 50){
canal.setChildIndex(current, images.length-5);
current.y=0;
setCards();
}
if(num1 > 50 && num1 < 80){
canal.setChildIndex(current, images.length-4);
current.y=0;
setCards();
}
if(num1 > 80 && num1 < 110){
canal.setChildIndex(current, images.length-3);
current.y=0;
setCards();
}
if(num1 > 110 && num1 < 140){
canal.setChildIndex(current, images.length-2);
current.y=0;
setCards();
}
if(num1 > 140 && num1 < 170){
canal.setChildIndex(current, images.length-2);
current.y=0;
setCards();
}
if(num1 > 170){
canal.setChildIndex(current, images.length-1);
current.y=0;
setCards();
}
}
private function setCards():void{
var b:int = 0;
var a:int;
var cardsArray:Array = canal.getChildren();
for(a = 0;a < cardsArray.length; a++)
{
canal.getChildAt(a).x = 50+b;
b=b+30;
canal.getChildAt(a).y=0;
}
}
]]>
</mx:Script>
</mx:Application>
PS: I am trying to replace the drag and drop events with mouse events and get the same functionality using mouse events. Please somebody help me in this.
Hope Below Code may help you: - You can use Drag and drop as per below code and create it in AS. I have created it in MXML which will give you some idea what you are looking for: -
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.core.DragSource;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.managers.DragManager;
private function doDragEnter(event:DragEvent):void
{
DragManager.acceptDragDrop(UIComponent(event.target));
}
private function doDragDrop(event:DragEvent):void
{
var img:RummyItemRenderer;
if (event.dragInitiator.parent == mainCanvas)
{
img = event.dragInitiator as RummyItemRenderer;
//mainCanvas.swapChildren(img, event.currentTarget as RummyItemRenderer);
var index:Number = mainCanvas.getChildIndex(event.currentTarget as RummyItemRenderer);
mainCanvas.removeChild(img);
mainCanvas.addChildAt(img,index);
setCardsPosition();
}
}
private function setCardsPosition():void{
var b:int = 0;
var a:int;
var cardsArray:Array = mainCanvas.getChildren();
for(a = 0;a < cardsArray.length; a++)
{
mainCanvas.getChildAt(a).x = 50+b;
b = b+30;
mainCanvas.getChildAt(a).y=20;
}
}
private function doDragStart(event:MouseEvent):void
{
var dragInitiator:RummyItemRenderer = event.currentTarget as RummyItemRenderer;
var dragSource:DragSource = new DragSource();
DragManager.doDrag(dragInitiator, dragSource, event);
}
]]>
</fx:Script>
<mx:Canvas id="mainCanvas" backgroundColor="#DDDDDD" width="400" height="200" x="50" y="50">
<local:RummyItemRenderer id="firstID" x="{mainCanvas.x}" y="20" width="200" height="80%" backgroundColor="#FF0000"
mouseDown="doDragStart(event)" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"
setImageSource="myImageURL"/>
<local:RummyItemRenderer id="secondID" x="{mainCanvas.x + 30}" y="20" width="200" height="80%" backgroundColor="#00FF00"
mouseDown="doDragStart(event)" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"
setImageSource="myImageURL"/>
<local:RummyItemRenderer id="thirdID" x="{mainCanvas.x + 60}" y="20" width="200" height="80%" backgroundColor="#0000FF"
mouseDown="doDragStart(event)" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)"
setImageSource="myImageURL"/>
</mx:Canvas>
</s:Application>
RummyItemRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
[Bindable]
private var _setImageSource:String;
public function get setImageSource():String
{
return _setImageSource;
}
public function set setImageSource(sourceURL:String):void
{
_setImageSource = sourceURL;
}
]]>
</fx:Script>
<s:Image id="imageID" source="{_setImageSource}"/>
</mx:Canvas>
Related
I am trying to put a gap of 20-30px between the Alert box buttons(YES and NO).
but unable to find such styling point in flex. I have tried horizontal-gap, and also padding, but in vain.
Below is the sample code i am trying, which i found when browsing through sites.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="Alert_style_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="showAlert()">
<!-- Used by the Alert control. -->
<mx:String id="message">The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.</mx:String>
<mx:String id="title">The quick brown fox jumped over the lazy dog?</mx:String>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var a:Alert;
private function showAlert():void {
Alert.yesLabel = "Yes";
Alert.noLabel = "No";
Alert.buttonWidth = 50;
a = Alert.show(
message,
title,
Alert.NO | Alert.YES
);
/* Make the Alert form's text non-selectable. */
a.mx_internal::alertForm.mx_internal::textField.selectable = false;
}
]]>
</mx:Script>
<mx:Style>
Alert{
color : #124332;
background-color: #ffffff;
header-colors : #243322, #243322;
header-height:19;
drop-shadow-enabled: true;
drop-shadow-color :#243322;
corner-radius :6;
border-style :solid;
border-thickness: 1;
border-color : #243322;
footer-colors : #243322, #ffffff;
title-style-name : "title";
horizontal-gap:500;
horizontal-separator-skin:white;
}
.title{
font-family :Verdana;
font-size :10;
font-weight :bold;
color :#ffffff;
}
.alertButton {
letterSpacing: 0;
fontSize: 11;
cornerRadius: 10;
fontWeight: normal;
textRollOverColor: white;
color: red;
horizontal-gap:-500;
}
</mx:Style>
<!-- Click to launch Alert control. -->
<mx:Button label="Launch Alert" click="showAlert();" />
</mx:Application>
Try something like this:
Add FlexEvent.UPDATE_COMPLETE to alertForm in your alert:
a.mx_internal::alertForm.addEventListener(FlexEvent.UPDATE_COMPLETE, alertForm_updateHandler);
And in this handler copy some stuff from original alertForm updateDisplayList method:
private function alertForm_updateHandler(event:FlexEvent):void
{
var form:UIComponent = a.mx_internal::alertForm;
var buttons:Array = a.mx_internal::alertForm.mx_internal::buttons;
var newX:Number;
var newY:Number;
var newWidth:Number;
newWidth = buttons.length * (buttons[0].width + 120) - 120;
newX = Math.round((form.width - newWidth) / 2);
for (var i:int = 0; i < buttons.length; i++)
{
buttons[i].x = newX
buttons[i].tabIndex = i + 1;
newX += buttons[i].width + 120;
}
}
where 120 is your new gap.
Hope this can be useful.
The only idea I have is to implement a new class as a child of TitleWindow or Panel and to add all the features you want to have. I know it is not the best solution, but you can try it.
Here are my proposals:
//Application
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.events.CloseEvent;
private function onBtnClick():void
{
var title:String = "The quick brown fox jumped over the lazy dog?";
var message:String = "The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.";
AdvancedAlert.buttonWidth = 70;
AdvancedAlert.buttonGap = 50;
AdvancedAlert.commonWidth = 400;
AdvancedAlert.show(message, title, AdvancedAlert.YES | AdvancedAlert.NO | AdvancedAlert.CANCEL, this._closeHandler);
}
private function _closeHandler(evt:CloseEvent):void
{
switch (evt.detail)
{
case AdvancedAlert.YES:
trace("yes");
break;
case AdvancedAlert.NO:
trace("no");
break;
case AdvancedAlert.OK:
trace("ok");
break;
case AdvancedAlert.CANCEL:
trace("cancel");
break;
}
}
]]>
</fx:Script>
<mx:Button click="onBtnClick()" label="Alert"/>
</mx:Application>
//Alert implementation
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
layout="absolute"
width="{commonWidth}"
height="110"
styleName="titleWindow"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
creationComplete="onCreationComplete()" >
<fx:Style>
#namespace mx "library://ns.adobe.com/flex/mx";
.windowStyles {
color: #ffffff;
}
.titleWindow {
borderAlpha: 1.0;
borderColor: #8a9faa;
backgroundColor: #8a9faa;
cornerRadius: 5;
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Button;
import mx.core.FlexGlobals;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
public static const YES:uint = 0x0001;
public static const NO:uint = 0x0002;
public static const OK:uint = 0x0004;
public static const CANCEL:uint= 0x0008;
[Bindable]private var message:String;
[Bindable]public static var buttonGap:int = 20;
public static var buttonWidth:int = 80;
[Bindable]public static var commonWidth:int = 80;
[Bindable]private var buttonHeight:int = 25;
private var buttons:uint;
private var buttonNames:ArrayCollection = new ArrayCollection();
private function onCreationComplete():void
{
addButtons();
}
private function addButtons():void
{
buttonNames.removeAll();
hbButtons.removeAllChildren();
if ((YES & buttons) != 0)
buttonNames.addItem("Yes");
if ((NO & buttons) != 0)
buttonNames.addItem("No");
if ((OK & buttons) != 0)
buttonNames.addItem("Ok");
if ((CANCEL & buttons) != 0)
buttonNames.addItem("Cancel");
for each (var bn:String in buttonNames)
{
var btn:Button = new Button();
btn.width = buttonWidth;
btn.height = buttonHeight;
btn.label = bn;
btn.name = bn;
btn.addEventListener(MouseEvent.CLICK, onBtnClick);
hbButtons.addChild(btn);
}
}
private function onBtnClick(evt:Event):void
{
var currentButtonName:String = (evt.currentTarget as Button).name;
var closeEvent:CloseEvent = new CloseEvent(CloseEvent.CLOSE);
switch (currentButtonName)
{
case "Yes":
closeEvent.detail = YES;
break;
case "No":
closeEvent.detail = NO;
break;
case "Ok":
closeEvent.detail = OK;
break;
case "Cancel":
closeEvent.detail = CANCEL;
break;
}
this.dispatchEvent(closeEvent);
PopUpManager.removePopUp(this);
}
public static function show(message:String = "", title:String = "", buttons:uint = 0x4, closeHandler:Function = null):void
{
var advancedAlert:AdvancedAlert = new AdvancedAlert();
advancedAlert.message = message;
advancedAlert.title = title;
advancedAlert.buttons = buttons;
if (closeHandler != null)
advancedAlert.addEventListener(CloseEvent.CLOSE, closeHandler);
PopUpManager.addPopUp(advancedAlert, Sprite(FlexGlobals.topLevelApplication), true);
PopUpManager.centerPopUp(advancedAlert);
}
]]>
</fx:Script>
<mx:VBox id="vbMain" width="100%" height="100%">
<mx:Text id="txtMessage" text="{message}" width="100%" height="35" color="0xffffff" selectable="false"/>
<mx:HBox id="hbButtons" height="{buttonHeight}" width="100%" horizontalGap="{buttonGap}" horizontalAlign="center"/>
</mx:VBox>
</mx:TitleWindow>
I want to pass two parameter to nativeProcess.
While i am running exe file using windows command with parameter, it is working.
Command for window is "abc.exe a.txt b.txt"
How can I pass two parameters to the exe in that format using flex nativeProcess?
This is what I have so far:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var process:NativeProcess;
protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
{
if (NativeProcess.isSupported)
{
callExe();
}
else
{
textReceived.text = "NativeProcess not supported.";
}
}
public function callExe():void
{
var a_FilePath:String = File.applicationStorageDirectory.resolvePath("dist/a.txt").nativePath;
var b_FilePath:File = File.applicationStorageDirectory.resolvePath("dist/b.txt").nativePath;
if (Capabilities.os.toLowerCase().indexOf("win") > -1)
{
var file:File = File.applicationStorageDirectory.resolvePath("dist/abc.exe");
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
// i put the line below and it works in my case
nativeProcessStartupInfo.workingDirectory = File.applicationStorageDirectory.resolvePath();
nativeProcessStartupInfo.executable = file;
var args:Vector.<String> = new Vector.<String>();
args.push(a_FilePath);
args.push(b_FilePath);
nativeProcessStartupInfo.arguments = args;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
process.addEventListener(ProgressEvent.PROGRESS, progressEvent);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, errorData);
}
public function inputProgressListener(event:ProgressEvent):void
{
textReceived.text += "Input Progress Event";
}
public function onOutputData(event:ProgressEvent):void
{
textReceived.text += "Output Event";
}
public function progressEvent(event:ProgressEvent):void
{
textReceived.text += "Progress Event";
}
public function errorData(event:ProgressEvent):void
{
textReceived.text += "Error Event";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:TextInput id="textReceived" width="352" height="200"/>
</s:WindowedApplication>
I solved my puzzle by adding the line below in bold:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var process:NativeProcess;
protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
{
if (NativeProcess.isSupported)
{
callExe();
}
else
{
textReceived.text = "NativeProcess not supported.";
}
}
public function callExe():void
{
var a_FilePath:String = File.applicationStorageDirectory.resolvePath("dist/a.txt").nativePath;
var b_FilePath:File = File.applicationStorageDirectory.resolvePath("dist/b.txt").nativePath;
if (Capabilities.os.toLowerCase().indexOf("win") > -1)
{
var file:File = File.applicationStorageDirectory.resolvePath("dist/abc.exe");
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
// i put the line below and it works in my case
nativeProcessStartupInfo.workingDirectory = File.applicationStorageDirectory.resolvePath();
nativeProcessStartupInfo.executable = file;
var args:Vector.<String> = new Vector.<String>();
args.push(a_FilePath);
args.push(b_FilePath);
nativeProcessStartupInfo.arguments = args;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
process.addEventListener(ProgressEvent.PROGRESS, progressEvent);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, errorData);
}
public function inputProgressListener(event:ProgressEvent):void
{
textReceived.text += "Input Progress Event";
}
public function onOutputData(event:ProgressEvent):void
{
textReceived.text += "Output Event";
}
public function progressEvent(event:ProgressEvent):void
{
textReceived.text += "Progress Event";
}
public function errorData(event:ProgressEvent):void
{
textReceived.text += "Error Event";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:TextInput id="textReceived" width="352" height="200"/>
</s:WindowedApplication>
I am trying to create a custom progress bar which has common functionality implemented like twining and setting the total value etc.,
Every thing seems to be working but for some reason, percentComplete is always 0 instead of increasing the value even when I call setProgress()
Update1:
Also, the tweener is not calling the onUpdate function (old code)
Update2:
If I modified the onUpdate function like this, onComplete is called but onUpdateProgress is called only once
onUpdate:this.onUpdateProgress(getTimer()),
Old code (call to function from inside anonymous function)
onUpdate:function():void{this.onUpdateProgress(getTimer());}
This is my custom Progressbar mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:ProgressBar xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
indeterminate="false" labelPlacement="center" fontWeight="bold" textDecoration="none" fontStyle="normal" textAlign="center"
chromeColor="0xFFFFFF" mode="manual"
>
<fx:Script>
<![CDATA[
import caurina.transitions.Tweener;
import flash.utils.getTimer;
public var cancel:Boolean = false;
public const MESSAGE_TYPE_DELETE:String = "Delete";
public const MESSAGE_TYPE_REMOVE:String = "Remove";
public const MESSAGE_TYPE_COLLECT:String = "Collect";
public const MESSAGE_TYPE_MAINTAIN:String = "Maintain";
public const MESSAGE_TYPE_BUILD:String = "Build";
public const MESSAGE_TYPE_CONSTRUCT:String = "Construct";
private var _orgMessage:String;
private var _newMessage:String;
private var _completeMessage:String;
private var _lastValue:uint;
private var _tweenCompleted:Boolean;
private function onUpdateProgress(value:Number):void{
var txt:String;
if (!cancel){
Update3:
Below is where I am setting the progress
this.setProgress(value,_lastValue);
if (value == _lastValue){
txt = _completeMessage;
_tweenCompleted = true;
}else{
txt = _newMessage;
}
label = txt + ":" + int(this.percentComplete).toString() + "%";
trace(value,_lastValue,this.percentComplete);
}
}
private function onComplete():void{
_tweenCompleted = true;
label = _completeMessage + ": 100%";
trace("completed");
}
public function startProgress(message:String,duration:int = 2):void{
_tweenCompleted = false;
_lastValue = getTimer() + duration * 1000;
_newMessage = ((message.charAt(message.length - 1) == "e")?message.substr(0,message.length - 1):message) + "ing";
_completeMessage = "Completed";
Tweener.addTween(this,
{
time:duration,
onUpdate:function():void{this.onUpdateProgress(getTimer());},
onComplete:this.onComplete(),
transition:"liner"
}
);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</mx:ProgressBar>
Main mxml
protected function startProgress(event:MouseEvent):void
{
this.removeAllElements();
pb = null;
pb = new FGProgressBar();
this.addElement(pb);
pb.startProgress("Remove",5);
}
I have trace commands in the onUpdateProgress()
trace(value,_lastValue,this.percentComplete);
value is the current progress value, which I am passing getTimer()
_lastValue is the total value of the progress bar, this is set in the initialzation (getTimer() + duration * 1000)
percentComplete is the progress status which should increase after setProgress()
its priting something like this
.
.
.
.
.
5162 8130 0
5210 8130 0
5244 8130 0
5754 8130 0
6262 8130 0
6771 8130 0
7279 8130 0
7787 8130 0
8295 8130 0
If you notice the trace, the value is incrementing, but the percentComplete is 0
Can someone tell me what I am missing?
I have used Flex SDK 4.6.0 and code works for me:
FGProgressBar.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:ProgressBar xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
indeterminate="false" labelPlacement="center" fontWeight="bold" textDecoration="none" fontStyle="normal" textAlign="center"
chromeColor="0xFFFFFF" mode="manual"
>
<fx:Script>
<![CDATA[
import caurina.transitions.Tweener;
import flash.utils.getTimer;
public var cancel:Boolean = false;
public const MESSAGE_TYPE_DELETE:String = "Delete";
public const MESSAGE_TYPE_REMOVE:String = "Remove";
public const MESSAGE_TYPE_COLLECT:String = "Collect";
public const MESSAGE_TYPE_MAINTAIN:String = "Maintain";
public const MESSAGE_TYPE_BUILD:String = "Build";
public const MESSAGE_TYPE_CONSTRUCT:String = "Construct";
private var _orgMessage:String;
private var _newMessage:String;
private var _completeMessage:String;
private var _lastValue:uint;
private var _tweenCompleted:Boolean;
private function onUpdateProgress(value:Number):void{
var txt:String;
if (!cancel){
this.setProgress(value,_lastValue);
if (value == _lastValue){
txt = _completeMessage;
_tweenCompleted = true;
}else{
txt = _newMessage;
}
label = txt + ":" + int(this.percentComplete).toString() + "%";
trace(value,_lastValue,this.percentComplete);
}
}
private function onComplete():void{
_tweenCompleted = true;
label = _completeMessage + ": 100%";
trace("completed");
}
public function startProgress(message:String,duration:int = 2):void{
_tweenCompleted = false;
_lastValue = getTimer() + duration * 1000;
_newMessage = ((message.charAt(message.length - 1) == "e")?message.substr(0,message.length - 1):message) + "ing";
_completeMessage = "Completed";
Tweener.addTween(this,
{
time:duration,
onUpdate:function():void{this.onUpdateProgress(getTimer());},
onComplete:this.onComplete(),
transition:"liner"
}
);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</mx:ProgressBar>
Main.mxml
<?xml version="1.0"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
height="600">
<fx:Script><![CDATA[
protected function startProgress(event:MouseEvent):void
{
this.removeAllElements();
var pb:FGProgressBar = null;
pb = new FGProgressBar();
this.addElement(pb);
pb.startProgress("Remove",5);
}
]]></fx:Script>
<s:Button click="startProgress(event)"/>
</s:Application>
Try to set mode="manual"
ex
<mx:ProgressBar
id = "idPercent"
labelPlacement = "center"
mode = "manual"/>
I installed red5 successfully, but when I try to connect to red5 to stream a video, the connection fails. If I use netstreaming(null), it works, but when I use red5, it doesn't.
I use following code to connect the stream:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init();">
<fx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
private var nc:NetConnection;
private var ns:NetStream;
private var video:Video;
private var meta:Object;
private var videoURL:String = "Fleximagteaser.flv";
private var nc1:NetConnection;
private var ns1:NetStream;
private var video1:Video;
private var meta1:Object;
private function init():void {
//video1
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
nc = new NetConnection();
nc.connect("rtmp://localhost/demo");
ns = new NetStream(nc);
ns.play(videoURL);
ns.client = nsClient;
video = new Video();
video.attachNetStream(ns);
uic.addChild(video);
}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.
video.width = item.width;
video.height = item.height;
// Resize UIComponent to same size as Video object.
uic.width = video.width;
uic.height = video.height;
panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VBox>
<mx:Panel id="panel" visible="false">
<mx:UIComponent id="uic" />
<mx:ControlBar>
<mx:Button label="Play/Pause" click="ns.togglePause();" />
<mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>
</mx:Panel>
</mx:VBox>
</s:Application>
Can anyone help?
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init();">
<fx:Script>
<![CDATA[
import flash.globalization.Collator;
import mx.utils.ObjectUtil;
private var nc:NetConnection;
private var ns:NetStream;
private var video:Video;
private var meta:Object;
private var videoURL:String = "Fleximagteaser.flv";
private var nc1:NetConnection;
private var ns1:NetStream;
private var video1:Video;
private var meta1:Object;
private function init():void {
//video1
nc = new NetConnection();
nc.connect("rtmp");
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS,onConnectionStatus);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,onErrorHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
}
private function onConnectionStatus(event:NetStatusEvent):void
{
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
ns = new NetStream(nc);
ns.play("videourl");
ns.client = nsClient;
video = new Video();
video.attachNetStream(ns);
uic.addChild(video);
}
private function onErrorHandler(event:AsyncErrorEvent):void{}
private function onSecurityError(event:SecurityErrorEvent):void{}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.
video.width = item.width;
video.height = item.height;
// Resize UIComponent to same size as Video object.
uic.width = video.width;
uic.height = video.height;
panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
public function onBWDone():void
{}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VBox>
<mx:Panel id="panel" visible="false">
<mx:UIComponent id="uic" />
<mx:ControlBar>
<mx:Button label="Play/Pause" click="ns.togglePause();" />
<mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>
</mx:Panel>
</mx:VBox>
How to create a polygon in Adobe flex 3.0
You draw a bunch of lines connecting the points of the polygon.
As a quick example:
function drawPolygon(first, ... rest) {
graphics.moveTo(first.x, first.y);
for(var i = 0; i < rest.length; i++) {
graphics.lineTo(rest[i].x, rest[i].y);
}
graphics.lineTo(first.x, first.y);
}
May be some minor syntax errors, but you get the idea. You'd call it by passing a bunch of Point objects indicating the points of the polygon.
Try this sample
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags">
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.SpatialReference;
import com.esri.ags.Units;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.Polygon;
import com.esri.ags.geometry.Polyline;
import com.esri.ags.utils.GeometryUtil;
import mx.utils.StringUtil;
private const sr:SpatialReference = new SpatialReference(4326);
protected function onCreatePolyline(event:MouseEvent):void
{
addMessage("Create polyline clicked");
var pts:Array = new Array();
for (var i:int; i < 10; i++) // add 10 random points to path
{
var pt:MapPoint = new MapPoint(Math.random()*10000, Math.random()*10000, sr);
pts.push(pt);
}
var pl:Polyline = new Polyline(new Array(pts), sr);
var lengths:Array = GeometryUtil.geodesicLengths(new Array(pl), Units.KILOMETERS);
if (lengths != null && lengths.length > 0)
{
addMessage(StringUtil.substitute("polyline created with length {0} km", lengths[0]));
}
addGraphic(pl);
}
protected function onCreatePolygon(event:MouseEvent):void
{
addMessage("Create polygon clicked");
var pts:Array = new Array();
for (var i:int; i < 10; i++) // add 10 random points to ring
{
var pt:MapPoint = new MapPoint(Math.random()*10000, Math.random()*10000, sr);
pts.push(pt);
}
var pg:Polygon = new Polygon(new Array(pts), sr);
var areas:Array = GeometryUtil.geodesicAreas(new Array(pg), Units.SQUARE_KILOMETERS);
if (areas != null && areas.length > 0)
{
addMessage(StringUtil.substitute("polygon created with area {0} kmĀ²", Math.abs(areas[0])));
}
addGraphic(pg);
}
private function addMessage(message:String):void
{
log.text = StringUtil.substitute("> > > {0}\n{1}", message, log.text);
}
private function addGraphic(geometry:Geometry):void
{
var gr:Graphic = new Graphic(geometry);
grLayer.clear();
var grId:String = grLayer.add(gr);
addMessage(StringUtil.substitute("graphic added with id='{0}'", grId));
map.initialExtent = geometry.extent;
map.zoomToInitialExtent();
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout gap="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10"/>
</s:layout>
<s:Button label="Create polyline"
click="onCreatePolyline(event)"/>
<s:Button label="Create polygon"
click="onCreatePolygon(event)"/>
<s:TextArea id="log"
width="100%"
height="100%"/>
<esri:Map id="map"
zoomSliderVisible="false"
minHeight="200"
width="100%">
<esri:GraphicsLayer id="grLayer" />
</esri:Map>
</s:Application>