So here is the mxml i would like to get working:
<?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">
<fx:Script>
<![CDATA[
import argoseye.main.Golem;
import mx.collections.ArrayCollection;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.InvokeEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
protected function button1_clickHandler(event:MouseEvent):void
{
var ro:RemoteObject = new RemoteObject("destination");
ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
ro.addEventListener(InvokeEvent.INVOKE,onInvoke);
var token:AsyncToken = new AsyncToken();
token.addResponder(new AsyncResponder(onResult,onFault));
token = ro.getCells();
textfeld.text = textfeld.text + "Clickhandler called .... \n";
}
public function onResult(event:ResultEvent,token:Object):void {
textfeld.text = textfeld.text + "Resulthandler called .... \n";
var cellList:ArrayCollection = event.result as ArrayCollection;
}
public function onFault(event:FaultEvent,token:Object):void
{
textfeld.text = textfeld.text + "Faulthandler called .... \n";
}
public function onInvoke(event:InvokeEvent):void {
textfeld.text = textfeld.text + "Invokehandler called .... \n";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
<s:TextArea x="1022" y="183" id="textfeld"/>
</s:Application>
The output is
Invokehandler called ....
Clickhandler called ....
The Resulthandler doesnt get called, allthough the BlazeDS Console registers an successfull Resultevent. What do I do wrong?
Edit: I tried exporting the procedure into a class, which is supposed to manage these things.
package argoseye.main
{
import flash.events.Event;
import mx.collections.ArrayCollection;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
public class Schem
{
public var info:String="";
public function Schem()
{
}
public function loadCurrentSchem():void
{
var ro:RemoteObject = new RemoteObject("Hibernatetest");
ro.endpoint = "http://jesus/blazeds/messagebroker/amf";
var token:AsyncToken = ro.getCells();
token.addResponder(new AsyncResponder(onResult,onFault));
info = info + "Loader Called ...";
}
public function onResult(event:ResultEvent,token:Object):void {
var cellList:ArrayCollection = event.result as ArrayCollection;
info = info + "Resulthandler Called";
}
public function onFault(event:FaultEvent,token:Object):void
{
}
//Eventhandlers
//Getters, Setters
}
}
If i call it, it doesnt reach the eventhandler. Where is my mistake?
Your error lies in these lines:
var token:AsyncToken = new AsyncToken();
token.addResponder(new AsyncResponder(onResult,onFault));
token = ro.getCells();
You're creating a new token on line 1.
You assign a responder on line 2.
And then you reassign the token on line 3.
What you do on line 3 is effectively creating a new token, thus it doesn't have the responder attached to it, because it's a new instance.
So it should be:
var token:AsyncToken = ro.getCells();
//ro.getCells() will return a new instance of AsyncToken
token.addResponder(new AsyncResponder(onResult,onFault));
Use the following code:
<fx:Script>
<![CDATA[
import argoseye.main.Golem;
import mx.collections.ArrayCollection;
import mx.rpc.AsyncResponder;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.InvokeEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
protected function button1_clickHandler(event:MouseEvent):void
{
var ro:RemoteObject = new RemoteObject("destination");
ro.endpoint = "http://Jesus/blazeds/messagebroker/amf";
ro.addEventListener(InvokeEvent.INVOKE,onInvoke);
var token:AsyncToken = ro.getCells();
token.addResponder(new AsyncResponder(onResult,onFault));
textfeld.text = textfeld.text + "Clickhandler called .... \n";
}
public function onResult(event:ResultEvent,token:Object):void {
textfeld.text = textfeld.text + "Resulthandler called .... \n";
var cellList:ArrayCollection = event.result as ArrayCollection;
}
public function onFault(event:FaultEvent,token:Object):void
{
textfeld.text = textfeld.text + "Faulthandler called .... \n";
}
public function onInvoke(event:InvokeEvent):void {
textfeld.text = textfeld.text + "Invokehandler called .... \n";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button x="1093" y="575" label="Button" click="button1_clickHandler(event)"/>
<s:TextArea x="1022" y="183" id="textfeld"/>
Related
I'm not able to set the Label of List Control which I first save to SQLite database and then show that as lebelField of List control my code is following :
List of Cities mxml is :
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Cities"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import model.DataModel;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.events.IndexChangedEvent;
import spark.components.SplitViewNavigator;
import spark.components.ViewNavigator;
import spark.transitions.ViewTransitionBase;
protected function myList_changeHandler():void {
// Create a reference to the SplitViewNavigator.
var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
// Create a reference to the ViewNavigator for the Detail frame.
var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(1) as ViewNavigator;
detailNavigator.transitionsEnabled = false;
// Change the view of the Detail frame based on the selected List item.
detailNavigator.pushView(DisplayContents, list_of_cities.selectedItem);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%">
<s:List id="list_of_cities" height="100%" width="100%" change="myList_changeHandler();"
dataProvider="{DataModel.getInstance().cityList}">
</s:List>
</s:VGroup>
city value object is ::
package valueobject
{
[Bindable]
public class CityValueObject
{
public var id:uint;
public var nameofcity:String;
}}
and DataModel is ::
package model
{
import flash.data.SQLConnection;
import mx.collections.ArrayCollection;
[Bindable]
public class DataModel
{
public var connection:SQLConnection;
public var cityList:ArrayCollection = new ArrayCollection();
public var logs:String="Application Logs........\n";
public static var _instance:DataModel;
public static function getInstance():DataModel
{
if(_instance == null)
{
_instance = new DataModel();
}
return _instance;
}
}}
and CityUtilities class is:
package utillities
{
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import model.DataModel;
import mx.collections.Sort;
import mx.collections.SortField;
import valueobject.CityValueObject;
public class CityUtils
{
public static function getAllCities():void
{
var contactListStatement:SQLStatement = new SQLStatement();
contactListStatement.sqlConnection = DataModel.getInstance().connection;
contactListStatement.text = "SELECT * FROM CITYNAME";
contactListStatement.execute();
var result:SQLResult = contactListStatement.getResult();
if( result.data!=null)
{
DataModel.getInstance().cityList.removeAll();
for(var count:uint=0;count<result.data.length;count++)
{
var cityVO:CityValueObject = new CityValueObject();
cityVO.id = result.data[count].id;
cityVO.nameofcity = result.data[count].city;
DataModel.getInstance().cityList.addItem(cityVO);
}
}
sortData();
}
public static function sortData():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "nameofcity";
dataSortField.numeric = false;
/* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
/* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */
DataModel.getInstance().cityList.sort = numericDataSort;
DataModel.getInstance().cityList.refresh();
}
public static function updateLog(newLog:String):void
{
DataModel.getInstance().logs += new Date().time+" :-> "+newLog+"\n";
}
}}
Please tell me how to set labelField according to SQLite nameofcity column thanks in advance
You need to display nameofcity means set LabelField property for spark list like following
<s:VGroup width="100%" height="100%">
<s:List id="list_of_cities" height="100%" width="100%" labelField="nameofcity" change="myList_changeHandler();"
dataProvider="{DataModel.getInstance().cityList}">
</s:List>
if it shows [object CityValueObject] then create custom ItemRenderer then override data method
override public function set data(value:Object):void
{
super.data = value;
var vo:CityValueObject=value as CityValueObject;
lblCityName.text = vo.nameofcity.toString();
}
All other code is correct, but mistake is that I placed
for(var count:uint=0;count<result.data.length;count++)
{
var cityVO:CityValueObject = new CityValueObject();
cityVO.id = result.data[count].id;
//cityVO.nameofcity = result.data[count].city; // Here I should Have written like
cityVO.nameofcity = result.data[count].nameofcity;// this works as I needed
DataModel.getInstance().cityList.addItem(cityVO);
}
I'm trying to emebed a simple OSMF player into my fex application. But it's not working. Here's my code :
<?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" applicationComplete="init()" >
<fx:Script>
<![CDATA[
import org.osmf.media.MediaPlayerSprite;
import org.osmf.media.URLResource;
protected function init():void{
var sprite:MediaPlayerSprite = new MediaPlayerSprite();
sprite.resource= new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.flv");
container.addChild(sprite);
}
]]>
</fx:Script>
<mx:UIComponent id="container" width="640" height="360"/>
I'm having a white screen when running the application
Thanks
here's the pure AS for how to do it:
package {
import flash.display.Sprite;
import org.osmf.media.MediaPlayerSprite;
import org.osmf.media.URLResource;
import org.osmf.media.DefaultMediaFactory;
public class SimpleOSMFPlayer extends flash.display.Sprite {
public static const PATH:String = "path/to/your/video.ext";
public var playerSprite:MediaPlayerSprite;
public var mediaFactory:DefaultMediaFactory;
public function SimpleOSMFPlayer() {
playerSprite = new MediaPlayerSprite();
var resource:URLResource = new URLResource(PATH);
mediaFactory = new DefaultMediaFactory();
playerSprite.media = mediaFactory.createMediaElement(resource);
addChild(playerSprite);
}
}
}
for flex, add the playerSprite to your UIComponent container instead of the sprite on the last line.
I have a datagrid that's using a custom itemrender with a button in it. I have a problem whereby when I click on a button the datagrid list scrolls its self. How can I prevent this behaviour?
Extended datagrid
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
doubleClickEnabled="false"
alternatingItemColors="[#ffffff, #f1f1f1]"
mouseDown="mdhandler(event)"
sortableColumns="true"
xmlns:datagrids="components.content.contents.datagrids.*"
creationComplete="_creationcomplete(event)">
<mx:Script>
<![CDATA[
import mx.binding.utils.BindingUtils;
import components.preview.PreviewPlayEvent;
import mx.controls.Button;
import components.preview.PreviewPlay;
import components.content.contents.FixedHelp.FixedHelp;
import mx.events.FlexEvent;
import mx.core.Application;
import mx.events.ToolTipEvent;
import flash.utils.describeType;
import mx.utils.ObjectUtil;
import components.remix.PadDisplay.PadContent;
import components.remix.PadDisplay.PalletteCode;
import mx.core.IUIComponent;
import mx.controls.Image;
import mx.managers.DragManager;
import mx.core.DragSource;
import mx.events.DragEvent;
// Embed icon image.
[Embed(source='assets/proxy.png')]
public var dragImg:Class;
private var _scrollEnabled:Boolean=true;
private var _currentpath:String="";
public static const TYPE_ARRAY:Array=["loop", "one-shot sample", "stem", "track"]
private function _creationcomplete(e:FlexEvent=null):void
{
addEventListener(Event.ENTER_FRAME, enterframe, false, 0, true);
addEventListener(PreviewPlayEvent.PLAY, previewplayrequest, false, 0, true);
addEventListener(PreviewPlayEvent.STOP,previewstoprequest,false,0,true)
}
private function previewplayrequest(e:PreviewPlayEvent):void
{
_currentpath=e._path;
//Application.application.previewplay(e._path)
invalidateList();
}
private function previewstoprequest(e:PreviewPlayEvent):void
{
_currentpath="";
//Application.application.previewplay(e._path)
invalidateList();
}
public function get critera():String
{
return _currentpath;
}
public function set criteria(value:String):void
{
_currentpath=value;
}
private function enterframe(e:Event):void
{
if (Application.application.hashelp == false)
{
}
else
{
removeEventListener(Event.ENTER_FRAME, enterframe);
var xml:XML=Application.application.helpxml;
var fh:FixedHelp=Application.application.fixedhelp;
var helptext:String=Application.application.helpxml.studio.loops.text;
fh.addItem(helptext, this);
}
}
private function mdhandler(e:MouseEvent):void
{
describeType(e.currentTarget)
e.currentTarget.toString()
if (e.currentTarget.selectedItem != null && getQualifiedClassName(e.target) != "mx.controls::Button")
{
_scrollEnabled=false
var dragdata:XML=XML(e.currentTarget.selectedItem) as XML
var ds:DragSource=new DragSource()
var dragdataasObject:Object=ObjectUtil.copy(e.currentTarget.selectedItem)
ds.addData(dragdataasObject, PadContent.LOOP_FORMAT);
//trace(ds.dataForFormat(PadContent.LOOP_FORMAT)) // I expect xml data to trace out here but it does not
var imageproxy:Image=new Image();
imageproxy.source=dragImg;
imageproxy.height=40;
imageproxy.width=40;
DragManager.doDrag(this, ds, e, imageproxy, (this.x - e.stageX) + 40, (this.y - e.stageY) + 130)
this.selectedItem=null;
}
else
{
e.stopImmediatePropagation();
}
}
private function userLabelFunction(item:Object, column:DataGridColumn):String
{
var newstr:String=new String(item.t + "\n" + TYPE_ARRAY[item.ty])
return newstr;
}
private function catFunction(item:Object, column:DataGridColumn):String
{
var newstr:String=TYPE_ARRAY[item.ty];
return newstr;
}
private function bpmFunction(item:Object, column:DataGridColumn):int
{
var newstr:Number=new Number(item.bp);
return newstr;
}
private function beatCountFunction(item:Object, column:DataGridColumn):int
{
var newstr:int=new int(item.bc);
return newstr;
}
private function sortbpm(obj1:Object, obj2:Object):int
{
var valueA:Number=obj1.bp;
var valueB:Number=obj2.bp;
return ObjectUtil.numericCompare(valueA, valueB);
}
private function sortbeatcount(obj1:Object, obj2:Object):int
{
var valueA:Number=obj1.bc;
var valueB:Number=obj2.bc;
return ObjectUtil.numericCompare(valueA, valueB);
}
public function get scrollEnabled():Boolean
{
return _scrollEnabled;
}
public function set scrollEnabled(value:Boolean):void
{
_scrollEnabled=value;
}
override protected function dragScroll():void
{
if (_scrollEnabled)
{
super.dragScroll();
}
}
]]>
</mx:Script>
<mx:columns>
<mx:DataGridColumn dataField="r"
headerText=""
itemRenderer="components.content.contents.datagrids.ImageRendererLoops"/>
<mx:DataGridColumn dataField="t"
headerText="Title"
labelFunction="userLabelFunction"/>
<mx:DataGridColumn dataField="bc"
headerText="Beats"
labelFunction="beatCountFunction"
sortCompareFunction="sortbeatcount"/>
<mx:DataGridColumn dataField="BPM"
headerText="BPM"
labelFunction="bpmFunction"
sortCompareFunction="sortbpm"/>
<mx:DataGridColumn itemRenderer="components.preview.PreviewPlay"/>
</mx:columns>
</mx:DataGrid>
Item Renderer
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.controls.listClasses.IDropInListItemRenderer">
<mx:Script>
<![CDATA[
import mx.controls.DataGrid;
import components.content.contents.datagrids.LoopMastersDataGrid;
import components.remix.PadDisplay.PadContent;
import mx.controls.listClasses.BaseListData;
[Embed(source='assets/play_20.png')]
[Bindable]
public var play20Img:Class;
public static const PLAYING:String="playing";
public static const LOADING:String="loading";
public static const IDLE:String="idle";
private var _listData:BaseListData;
private var _bpm:int;
private var _path:String;
private var _state:String="idle";
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData=value;
var criteria:String = (_listData.owner as LoopMastersDataGrid).critera;
if(this._path==criteria)
{
// this track is playing
previewbutton.styleName="stopPreviewButtonStyle";
}else
{
// this track is not playing
previewbutton.styleName="playPreviewButtonStyle";
}
//trace("list data crit=="+criteria);
}
override public function set data(value:Object):void
{
super.data=value;
this._path=new String(PadContent.LOOP_ROOT + value.r + "/" + value.u + ".rocudo");
this._bpm=value.bp;
//trace(this._path);
}
private function sendPreviewRequest(event:Event):void
{
switch(this._state)
{
case(PreviewPlay.IDLE):
(listData.owner as LoopMastersDataGrid).dispatchEvent(new PreviewPlayEvent(PreviewPlayEvent.PLAY,this._bpm,this._path));
break;
case(PreviewPlay.LOADING):
// preview play probably shouldnt care about loading
break;
case(PreviewPlay.PLAYING):
(listData.owner as LoopMastersDataGrid).dispatchEvent(new PreviewPlayEvent(PreviewPlayEvent.STOP,this._bpm,this._path));
break;
}
//dispatchEvent(new PreviewPlayEvent(PreviewPlayEvent.PLAY,this._bpm,this._path));
}
/** override protected function commitProperties():void
{
super.commitProperties();
this._state=PreviewPlay.IDLE;
}**/
]]>
</mx:Script>
<mx:Button id="previewbutton"
width="20"
height="20" click="sendPreviewRequest(event)" styleName="playPreviewButtonStyle">
</mx:Button>
</mx:HBox>
Update
I removed my mouse down handler from the datagrid and removed the cusom component. Clicking on a item in the datagrid makes the datagrid scroll so that the item selected appears first in the list. This is the behaviour I need to stop.
I'm using the Swiz framework and I'm trying to update my viewstack's selectedIndex with a bindable property. It gets to my event handler which updates the bindable variable but the Main app file's viewstack never realizes it. What could be the issue?
thx
-Mike
================================
MAIN APP FILE
<mx:Script>
<![CDATA[
import reg.model.ApplicationViewModel;
import beyaz.reg.swiz.SwizBeans;
import org.swizframework.Swiz;
[Autowire(bean="applicationViewModel")]
[Bindable]
public var applicationViewModel:ApplicationViewModel;
private function preInitialize():void {
Swiz.loadBeans( [ SwizBeans ] );
}
]]>
</mx:Script>
<mx:ViewStack id="theViewstack" **selectedIndex=" {applicationViewModel.mainViewIndex}"** width="100%" height="100%">
<prescreen:Prescreen id="prescreenView"/>
<login:Login id="loginView"/>
<profile:Profile id="profileView"/>
</mx:ViewStack>
=================================
ApplicationViewModel
package com.reg.model
{
public class ApplicationViewModel
{
public static const PRESCREEN_VIEW:int = 0;
public static const LOGIN_VIEW:int = 1;
public static const PRSNL_INFO_VIEW:int = 2;
[Bindable]
public var message:String = "";
[Bindable]
public var mainViewIndex:int = PRESCREEN_VIEW;
}
}
===========================
Controller
package com.reg.controller
{
import com.reg.model.ApplicationViewModel;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.DynamicEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.core.Application;
import org.swizframework.Swiz;
import org.swizframework.controller.AbstractController;
public class PrescreenController// extends AbstractController
{
public static const START_REGISTRATION:String = "startReg";
[Autowire(bean="applicationViewModel")]
[Bindable]
public var applicationViewModel:ApplicationViewModel;
[Mediate(event="startReg")]
public function startReg():void
{
//CODE GETS TO HERE!
applicationViewModel.mainViewIndex = ApplicationViewModel.PRSNL_INFO_VIEW;
}
}
}
I got bit by this problem just last week.
Put your [Bindable] tag before the other tags. For some reason the Flex compiler doesn't fold in the appropriate PropertyChangeEvent dispatching unless you put the [Bindable] tag first.
In my AIR application I am having problems catching dispatched events in my eventmap.
The class that is dispatching the events looks like this:
Shortcuts.as
[Event(name="centeredZoomOut", type="flash.events.Event")]
public class Shortcuts extends EventDispatcher
{
// Event Names
public static const CENTERED_ZOOM_OUT:String = "centeredZoomOut";
public function Shortcuts(target:IEventDispatcher=null)
{
super(target);
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
private function onKeyUp(event:KeyboardEvent):void
{
this.dispatchEvent(new Event(CENTERED_ZOOM_OUT, true));
}
}
I know that the event is getting dispatched from debugging it, but it is not getting caught by the following eventmap.
ShortcutMap.mxml
<?xml version="1.0" encoding="utf-8"?>
<EventMap
xmlns="http://mate.asfusion.com/"
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import models.Shortcuts;
]]>
</mx:Script>
<EventHandlers type="{ Shortcuts.CENTERED_ZOOM_OUT }">
<MethodInvoker generator="{ShortCutExample}" method="showAlert" arguments="{['centeredZoom']}" />
</EventHandlers>
Here is the main application file called "ShortCutExample"
ShortCutExample.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:maps="maps.*"
layout="absolute"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import models.Shortcuts;
private var shortcuts:Shortcuts;
private function init():void
{
this.shortcuts = new Shortcuts();
}
public function showAlert(value:String):void
{
Alert.show(value);
}
]]>
</mx:Script>
<maps:ShortcutMap/>
</mx:WindowedApplication>
Why is my eventmap not catching the event?
Because I was not adding the object to the display list and it did not extend DisplayObject the dispatched events were not being caught by the eventmap. To solve this problem create a private variable of type GlobalDispatcher and dispatch your events from that variable.
private var dispatcher:GlobalDispatcher = new GlobalDispatcher();
...
this.dispatcher.dispatchEvent(new ShortCutEvent(ShortCutEvent.CENTERED_ZOOM_OUT, true));