Binding in ActionScript
I want to do something like you can do in MXML like this:
<mx:Text text="Page {mainFramework.selectedIndex +1} of
{mainFramework.numChildren}"/>
Which shows in the text field Page 1 of 6 (for example)
but I want to do this in ActionScript.
I have the following in a creationComplete handler for a text
field:
BindingUtils.bindProperty(this,"text",framework,"selectedIndex");
Which works in that the selectedIndex of the ViewStack is
displayed, but
I want to add 1 to it and format it as per the MXML example.
currently
I just get 0 displayed where I want Page 1 of 6 (for example)
Any takers?
Thanks
Mark
DominicV wrote:
> Hi Mark,
>
> I've only been using Flex or a few days so I'm a bit of
a newbie to it! But I
> believe this should work...
>
> {
> ...
> BindingUtils.bindSetter(watcherListener, framework,
"selectedIndex", true);
> }
>
> // Event listener when binding occurs.
> public function watcherListener(object:*):void {
> an_object.text = "Page " + object.toString() + " of 6";
> }
>
> This worked for me when doing an async webservice call
and needing to watch
> for when a variable changed and bind to it.
>
>
>
Thanks for the reply...That is very close and I managed to do
what I
wanted based on your response.
Thanks again.
Mark
Similar Messages
-
How to bind XML in Actionscript?
I'm having difficulty working with binding in actionscript. In MXML I can use the following line:
<mx:Label x="117" y="40" text=" {stationXML.getItemAt(Station-1).CDL0.@value}" id="lblTest"/>
However, in actionscript, I cannot seem to get the binding to work! I tried the following:
BindingUtils.bindProperty(lblTest,"text",stationXML.getItemAt(Station-1).CDL0,"value");
Any ideas how I can do this in Actionscript? I need to do it in ActionScript becuase the "CDL0" value will need to be replaced at times with "CDL1", "CDL2", etc...I solved the issue, so if anyone else has the same problem, here's what I did (after much aggravation):
The reason I didnt use MXML binding was because I wanted to be able to change it from "CDL0" to "CDL1" to "CDL3" without manually changing bindings.
What I set in MXML for the text was:
{stationXML.getItemAt(Station-1).child(cdlstr).@value}
where 'cdlstr' was a public string declared (and set) elsewhere in the program.
So I could make 'cdlstr' = "CDL0" or "CDL1" or even "CDL" + i (if I wanted to make life easy). Just needed to remember to make 'cdlstr' a bindable variable or else it all falls apart.
Hope it helps someone else. -
Binding ActionScript object to webservice
Hi,
Can someone please provide me with simple example as to how
to bind an ActionScript object to the webservice.
The Scenario is I have an actionscript class. I have the
webservice in the mail mxml. I want to create an object of the
class and want to bind that object to the webservice rather than
binding each of the property.
Thanks in advance.Do not bind directly to a webService result. Use a result
handler, and assign the result to a bindable variable. Bind to
that.
To intercept binding events in AS code, use a ChangeWatcher.
Tracy -
If I set binding in ActionScript like this:
BindingUtils.bindProperty(myText, "text", myTI, "text");
How can I break that binding if desired?BindingUtils.bindProperty() returns a ChangeWatcher instance. Cache that an call
unwatch() on it when needed.
C -
A328 (dual sim) "Contact Binding" not working as expected
Hi, fellows!
On my A328 (dual SIM, Android 4.4.2) I wanted to use "Contact Binding" feature, so, in Settings -> All settings -> SIM management I put:
Default Settings section:
Voice call = Always ask
(possible 3 options: SIM1 | SIM2 | Always ask)
General Settings section:
Contact binding: I've binded some contacts to SIM1 and rest to SIM2.
However, whenever I make a call. a dialog pop-up asking what SIM to use; the SIM used to bind the contact is marked with a star symbol in the dialogue window.
Please note that I tried to set voice call default to SIM2. When I called a contact binded to SIM2, there was no dialogue pop-up, so it worked as expected. But when I called a contact binded to SIM1, the dialogue pop-up.
I expect that a contact binded to SIM1 to use SIM1 when I make a call, a contact binded to SIM2 to use SIM2, and a contact no assigned to pop-up the dialogue windows
Any idea to get rid of the dialogue and use directly the contact binding I set?Binding works one way. This means that textInput.text changes
to match the value of account.identifier, not the other way around.
While I think it's theoretically possible to create a binding the
other way (I haven't played with binding in ActionScript), it makes
more sense to listen to the TextInput's change event to get changes
to the text field.
Or, you can create a model in the MXML and bind one its
properties to the textinput's value. Look in the docs about the
mx:Model tag for details. -
in my project I used core data and binding to produce data on document based program.
I have used multiple entities and they worked fine and then they stopped working and I don't know why.
all the text fields now have "()" in them with space in between them, and will not add to the database. so the field shows a junk value and will not bind properly to the database.
how would I start to debug this I have been searching but I don't know where to start, mainly i dont know what the problem is.Binding works one way. This means that textInput.text changes
to match the value of account.identifier, not the other way around.
While I think it's theoretically possible to create a binding the
other way (I haven't played with binding in ActionScript), it makes
more sense to listen to the TextInput's change event to get changes
to the text field.
Or, you can create a model in the MXML and bind one its
properties to the textinput's value. Look in the docs about the
mx:Model tag for details. -
Howto dynamicly bind XML element to a TextInput using BindingUtils?
The question is: Howto dynamicly bind XML element to a
TextInput component using BindingUtils?
Now I use following codes:
<!--
[Bindable] private var xml: XML =
<item><label>list1</label></item>;
// initialize code for application's initialize event
private function init(): void {
BindingUtils.bindProperty(txtDemo, "text", xml, "label");
//click event
private function test(): void {
xml.label = "something";
// txtDemo.executeBindings(); //---- no use anymore
-->
<mx:TextInput id="txtDemo"/>
<mx:Button label="Test" click="test()"/>
My really idea is when bindable xml property is changed, then
the textinput will be updated as hoped. However, no update happens
to me when I click the Test button.
But, if I make codes like that:
<mx: TextInput id="txtDemo" text="{xml.label}"/>
the text will updated when xml changs.
So, what happened, I indeed need the dynamicly bind to the
textinput compont.
Help me. thanks.You could use an ObjectProxy since all subproperties will
then be bindable:
private var _xml:XML =
<item><label>list1</label></item>;
private var _opXML:ObjectProxy = new ObjectProxy(_xml);
then in your init() function you declare _opXML as the host
object with the bindable property "label"...
// initialize code for application's initialize event
public function init(): void {
BindingUtils.bindProperty(txtDemo, "text", _opXML, "label");
//click event
private function test(): void {
_opXML.label = "something";
You'll notice that if you check your original _xml.label
property with ChangeWatcher.canWatch(), it returns false. But if
you create a dedicated object with a property that can be declared
as bindable, canWatch() returns true. You'd probably be best off to
write a lightweight class that can act as your model if you want to
work with dynamic XML binding using Actionscript. This will allow
you to use a bindable getter and setter that will give you the
dynamic functionality you're looking for.
Hope that helps. -
Bind XML/A to OLAPDataGrid
Hi,
Is there a way to bind the XML/A result from an MDX query to an OLAPDataGrid
Thank youYou could use an ObjectProxy since all subproperties will
then be bindable:
private var _xml:XML =
<item><label>list1</label></item>;
private var _opXML:ObjectProxy = new ObjectProxy(_xml);
then in your init() function you declare _opXML as the host
object with the bindable property "label"...
// initialize code for application's initialize event
public function init(): void {
BindingUtils.bindProperty(txtDemo, "text", _opXML, "label");
//click event
private function test(): void {
_opXML.label = "something";
You'll notice that if you check your original _xml.label
property with ChangeWatcher.canWatch(), it returns false. But if
you create a dedicated object with a property that can be declared
as bindable, canWatch() returns true. You'd probably be best off to
write a lightweight class that can act as your model if you want to
work with dynamic XML binding using Actionscript. This will allow
you to use a bindable getter and setter that will give you the
dynamic functionality you're looking for.
Hope that helps. -
Hello. This is what I am trying to accomplish. I am making a
tabbed registration flash form and I would like the person
completing the form to see a total as he makes the selection for
what he will be attending. The way I approached the problem was to
bind an ActionScript function to the
GRANDTOTAL form field, but when the form finishes loading in
the browser, the
NaN error pops up. I tried to convert the field selections
explicitly to numbers to perform the addition, but it is obviously
not working. If anyone could shed some insight into this, that
would be great. Thank you in advance. The code for the tab that
handles the selection is below.
<!-- registration details tab -->
<cfformgroup type="page" label="Registration">
<cfformitem type="text">Your FULL NBBAN Registration
Includes: Admission to all Forums, Continental Breakfast,
Refreshment Breaks, Welcome Reception, Awards Dinner and
Luncheon.</cfformitem>
<cfformitem type="spacer" height="3" />
<cfformitem type="text">CONFERENCE REGISTRATION
FEES:</cfformitem>
<cfformgroup type="tile" height="650">
<cfformgroup type="horizontal">
<cfselect name="MemberQtyat250" size="1">
<option value=0>0</option>
<option value=250 selected>1</option>
<option value=500>2</option>
<option value=750>3</option>
<option value=1000>4</option>
<option value=1250>5</option>
</cfselect>
<cfformitem type="text">$250 per
MEMBER</cfformitem>
</cfformgroup>
<cfformgroup type="horizontal">
<cfselect name="NonMemberQtyat300" size="1">
<option value=0 selected>0</option>
<option value=300>1</option>
<option value=600>2</option>
<option value=900>3</option>
<option value=1200>4</option>
<option value=1500>5</option>
</cfselect>
<cfformitem type="text">$300 per
NON-MEMBER</cfformitem>
</cfformgroup>
<cfformgroup type="horizontal">
<cfselect name="GuestQtyat125" size="1">
<option value=0 selected>0</option>
<option value=125>1</option>
<option value=250>2</option>
<option value=375>3</option>
<option value=500>4</option>
<option value=625>5</option>
</cfselect>
<cfformitem type="text">$125 GUEST (accompanied by
MEMBER)</cfformitem>
</cfformgroup>
<cfformgroup type="horizontal">
<cfselect name="WelcomeReceptionQtyat75" size="1">
<option value=0 selected>0</option>
<option value=75>1</option>
<option value=150>2</option>
<option value=225>3</option>
<option value=300>4</option>
<option value=375>5</option>
</cfselect>
<cfformitem type="text">$75 WELCOME RECEPTION
ONLY</cfformitem>
</cfformgroup>
<cfformgroup type="horizontal">
<cfselect name="AwardsQtyat100" size="1">
<option value=0 selected>0</option>
<option value=100>1</option>
<option value=200>2</option>
<option value=300>3</option>
<option value=400>4</option>
<option value=500>5</option>
</cfselect>
<cfformitem type="text">$100 AWARDS AND RECOGNITION
CEREMONY ONLY</cfformitem>
</cfformgroup>
<cfformgroup type="horizontal">
<cfselect name="LuncheonQtyat75" size="1">
<option value=0 selected>0</option>
<option value=75>1</option>
<option value=150>2</option>
<option value=225>3</option>
<option value=300>4</option>
<option value=375>5</option>
</cfselect>
<cfformitem type="text">$75 LUNCHEON
ONLY</cfformitem>
</cfformgroup>
<cfformgroup type="horizontal">
<cfselect name="KingTourQtyat20" size="1">
<option value=0>0</option>
<option value=20 selected>1</option>
<option value=40>2</option>
<option value=60>3</option>
<option value=80>4</option>
<option value=100>5</option>
</cfselect>
<cfformitem type="text">$20 THE KING CENTER
TOUR</cfformitem>
</cfformgroup>
<cfformitem type="script">
function subTotal() {
var memberQty = registration.MemberQtyat250;
var nonmemberQty = registration.NonMemberQtyat300;
var guestQty = registration.GuestQtyat125;
var receptionQty = registration.WelcomeReceptionQtyat75;
var awardsQty = registration.AwardsQtyat100;
var luncheonQty = registration.LuncheonQtyat75;
var tourQty = registration.KingTourQtyat20;
var result = trace(Number(memberQty)) +
trace(Number(nonmemberQty)) + trace(Number(guestQty)) +
trace(Number(receptionQty)) + trace(Number(awardsQty)) +
trace(Number(luncheonQty)) + trace(Number(tourQty));
alert(result);
</cfformitem>
<cfformgroup type="horizontal">
<cfinput type="text" name="GRANDTOTAL" label="Total: $"
bind="{subTotal()}" />
</cfformgroup>
</cfformgroup>
</cfformgroup>You need to store the information user have input before
somewhere. You can store it in local shared object, which is dubbed
as a "flash cookie" -- Flash MX. Then you will retrieve it at
execute an autofill. If you store the user's info in a remote
database -- you can loadVars from you server with the form
information.
Search for SharedObject in flash help -- it is pretty
straight forward and simple.
I forgot to mention that you will need to compare entry in
the form field with the stored info on each key stroke, naturally,
and display results in an additional text field, etc.
Hope it helps... -
CFGRID Selected Item as Variable
Is it possible to set the value of a selected item in a
cfgrid to a variable?
I have tried this but it does not work:
<cfset UpdateID={recipegrid.selectedItem.RecipeID}>
(Throws an error)
also tried:
<cfset UpdateID="{recipegrid.selectedItem.RecipeID}">
(Just sets the variable to the string
{recipegrid.selectedItem.RecipeID} not the actual value from the
selected row.)
or
<cfset UpdateID='{recipegrid.selectedItem.RecipeID}'>
(Does the same as above.)
How can I do this?Your attempts don't work because they assign the Coldfusion
variable
UpdateID an Actionscript value
{recipegrid.selectedItem.RecipeID}.
Use cfinput's bind attribute. For example, the following code
binds the Actionscript value {recipeGrid.selectedItem.recipeID} to
the Coldfusion variable form.UpdateID when the form is submitted.
<cfif isDefined("form.UpdateID")>
UpdateID: <cfoutput>#form.UpdateID#</cfoutput>
</cfif>
<cfset recipes = "pasta,salad,meat">
<cfset ids = "1,2,3">
<cfform name="recipes" format="flash"
action="#cgi.script_name#">
<cfgrid name="recipeGrid">
<cfgridcolumn name="recipeID" header="Recipe ID">
<cfgridcolumn name="recipe" header="Recipe">
<cfloop index="i" from="1" to="#ListLen(recipes)#">
<cfgridrow data ="#ListGetAt(ids, i)#,#ListGetAt(recipes,
i)#">
</cfloop>
</cfgrid>
<cfinput name="UpdateID" type="text" label="Update ID"
width="100" bind="{recipeGrid.selectedItem.recipeID}" />
<cfinput name="sbmt" type="submit" value="Send">
</cfform> -
How to Assigning Binding Properties in ActionScript?
We all know that creating binding properties in MXML is straight-forward:
<MyComponent
myProperty="{bindableValue}"
/>
How can I do the same using only ActionScript? Following the above example:
var myComp :MyComponent = new MyComponent();
myComp.myProperty = ?????????;
Thanks!Use the BindingUtils class, specifically its static bindProperty method.
bindProperty(site:Object, prop:String, host:Object, chain:Object, commitOnly:Boolean = false)
The following documentation may be helpful as well:
http://www.flexafterdark.com/docs/Flex-Binding
http://livedocs.adobe.com/flex/3/langref/mx/binding/utils/BindingUtils.html
I hope that helps...
Ben Edwards -
ActionScript to bind XML data to components
How can I use ActionScript to bind XML data to a comboBox
component instead of using the component inspector? (I have done
the latter, successfully, but that doesn’t allow access to
the code - .)
My ActionScript so far imports the data (the trace picks it
up) – but the ‘cbType.dataProvider line’
doesn’t work. It works when I change the data provider to an
array – so what am I doing wrong?
MY CODE:
import mx.data.components.XMLConnector;
var xcFestival:XMLConnector = new XMLConnector();
xcFestival.ignoreWhite = true;
xcFestival.direction = "receive";
xcFestival.URL = "festivalItems.xml";
xcFestival.trigger();
//POPULATE THE COMPONENTS WITH THE DATA
var festXMLlistener:Object = new Object();
festXMLlistener.result = function(evt:Object) {
trace(xcFestival.results);
cbType.dataProvider = xcFestival.results;
xcFestival.addEventListener("result",festXMLlistener);This is on a stand - alone system
Using Designer ES ......
I saved the Form as an xdp form
and it seems as if all goes well until
View the data and nothing appears - or
just the names of the fields appear -
Binding Styles in Actionscript
Friends,
I have a Actionscript component which ofcourse is completely
developed in Actionscript ... no mxml.
I need to bind the some of the styles like gutterLeft etc to
variables. How would I do it?
BindingUtils.bindProperty(myChartObject, "gutterLeft", this,
"MyVariable); ... will not work."flexisawesome" <[email protected]> wrote in
message
news:gje2jh$95p$[email protected]..
> Amy,
> Thanks for your response but it dosent help. I dont
think I expressed my
> question very well. Let me try again.
>
> I have a Actionscript class that extends UIComponent and
I am trying to
> add
> chart objects to it. Here is my code that should explain
>
> public class MyCharts extends UIComponent {
> private var lineChart:LineChart;
> private var someDataProvider:ArrayCollection = new
> ArrayCollection([1,2,3]);
> public var dynamicGutterLeft:int = 25;
>
> override protected createChildren():void {
> lineChart = new LineChart();
> lineChart.dataProvider = someDataProvider
> //now I need to bind a style to a variable
> BindingUtils.BindProperty(lineChart, "gutterLeft", this,
> "dynamicGutterLeft");
> //The above line will give an error because lineChart
does not have a
> property called "gutterLeft"
> //question is how do I bind. This is a simple example to
explain my
> problem.
> //I understand that I could have get/set for
"dynamicGutterLeft" and
> in
> the set, I could do a setStyle.
> //but I really want to bind it.
> }
>
>
> }
>
You can want all you want, but you can't force Flex to do
something in a way
that it isn't interested in doing it. When I was in college,
one of my guy
friends told me this story. He was out with some female
friends of ours and
the same guy kept asking one of them to dance. She kept
saying no, and the
guy finally said "But I really _want_ to dance with you. My
friend stepped
in and said "Yeah. We tend to want things."
The only way to change a style is to call setStyle.
http://livedocs.adobe.com/flex/3/html/databinding_9.html.
HTH;
Amy -
Newbie: binding actionscript var to textinput
Hi,
I'm just starting with flex, and have a simple question on
bindings. I've created the following application (using flex3 beta
3, and flexbuilder):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
[Bindable]
public var customerName:String = "customerName";
]]>
</mx:Script>
<mx:TextInput text="{customerName}" x="187" y="92"/>
<mx:Text text="{customerName}" x="368" y="94"/>
<mx:Button click="customerName += 'z'" x="473" y="92"
label="add z"/>
</mx:Application>
The problem: the variable customerName isn't changed when i
enter some text in the textinput. Pressing the button does the
expected thing: changes the variable, which is displayed correctly
by the textinput and text components.
My goal is to create a datamodel using an actionscript
object. I've seen some examples where the datamodel is bound to the
textinput (the other way around), but it seems to me that it would
be better not to tie a datamodel to one single input component. I
may want to modify the data using multiple components.
Thanks,
AndrejMy 2 cents: There is often a misconception that when making a
variable bindable, it is a two-way binding, in other words, the
entity that is bound to the variable will be updated automatically
AND the variable will be updated if the entity's value changes (a
circular binding).
Making your variable [Bindable] means that there is a single
observer, like your TextInput, of a variable, like customerName. If
the customerName variable changes, then the TI will change, not the
other way around.
Your approach of using the Binding tag with a reciprocal
source and destination should be fine.
My approach usually is to set the initial value I want
displayed in the TI from elsewhere. Then the TI is strictly used as
the control to input data in order to update a variable on the
'change' event. I often bind to a function that'll automatically
perform XYZ for me on a specific event.
TS -
Unable to bind to properties of actionscript object
Hello Forum Folks,
I built a bread crumb object that extends UIComponent:
package com.XXX.bidboard
import mx.core.UIComponent;
public class BreadCrumb extends UIComponent
[Bindable]
private var _pageTitle:String;
[Bindable]
private var _component:String;
[Bindable]
private var _order:Number;
[Bindable]
private var _pageVisited:Boolean;
[Bindable]
private var _notLast:Boolean;
public function BreadCrumb()
super();
public function get pageTitle():String {
return _pageTitle
public function set pageTitle(value:String):void {
_pageTitle = value;
public function get component():String {
return _component
public function set component(value:String):void {
_component = value;
public function get order():Number {
return _order
public function set order(value:Number):void {
_order = value;
public function get pageVisited():Boolean {
return _pageVisited
public function set pageVisited(value:Boolean):void {
_pageVisited = value;
public function get notLast():Boolean {
return _notLast
public function set notLast(value:Boolean):void {
_notLast = value;
Then in an application object I try to create a BreadCrumb
object:
<bidboard:BreadCrumb
id="onePersonal"
pageTitle="Start"
component="personal_companies_wizard_start"
order="0"
pageVisited="true"
notLast="true" />
however, I get strange warnings:
warning: unable to bind to property 'notLast' on class
'com.XXX.bidboard::BreadCrumb'
warning: unable to bind to property 'pageTitle' on class
'com.XXX.bidboard::BreadCrumb'
warning: unable to bind to property 'pageVisited' on class
'com.XXX.bidboard::BreadCrumb'
Why? Everything seems to look correct. What is really strange
is that it only gives the warnings on notLast, pageTitle, and
pageVisited but not order or component. The only difference I can
tell betweeen the two groups are the fact that one group has
capital letters and other doesn't - However I can imagine this is
the cause of the problem. (I tried everything in lowercase and the
warning still appeared).
Any ideas? I'm willing to try anything to solve this mystery.
Did I miss something?
Thanks in advance!
--AndyAllow me to answer my own question. I found on Daniel's blog
http://life.neophi.com/danielr/2006/08/binding_error.html)
the answer to the unconverted Bindable metadata warning. Appearntly
if I switch the order of the setters and getters, such that the
setter show up first, the warning disappears. Not sure why the
flash engine needs it that way, but it does. All works now!
Thanks,
--Andy
Maybe you are looking for
-
Lost the ability to Spotlight Index my Time Machine drive
I have an external, Firewire Time Machine drive which has been working without problems up to now. This evening I had a backup which hung up in the "preparing" stage (no file transfers begun yet). When I went to look in the console, there was a devic
-
Cross-domain SWF loading doesn't work
I've been trying to get cross-domain SWF loading to work for a while now, but even though it works from the Flash IDE the loaded SWF is blank when I upload it to a webserver somewhere. And yes, both servers have a crossdomain.xml file in their root f
-
My icon for firefox on the desktop has a question mark on it why?
i have a question mark on my icon firefox which is on the desk top. why??
-
Milestone Based Payment - Activation Steps
Dear SAP PS Members I am trying to execute a milestone based Payment process in SAP PS module for managing the Invoice to be paid in my company. what I have understood up to now is it can be done using below steps - 1. Activity/Milestone Confirmatio
-
Error when launching transaction code CRMBS02
Hello all...whenever we attempt to launch the t-code CRMBS02 or BS02, we get a popup that says: Error in object editing: This syntax cannot be used for an object name Selecting the documentation drop down provides: Message no. TK103 Diagnosis The syn