Accesing mxml components from AS class
Hello,
on a CS6 <csxs:CSExtension> how do I refer to a component (say, a Button with id="myButton") in the main view from an Actionscript class?
The equivalent mx: way highlighted here: http://livedocs.adobe.com/flex/3/html/help.html?content=app_container_3.html)
TIA,
Davide
Apparently, the correct way is: FlexGlobals.topLevelApplication
(it seems like FB has some problems with both com.adobe.photoshop.Application and mx.core.Application.application in the same class - at least it fired a bunch of weird errors to me)
Davide
Similar Messages
-
How to Access MXML components from ActionScript class
Hi ,
I am having a Application Conataner , in which i am having a Form Container with some Label in it .
This is some thing similar to this as shown :
<Mx:Application>
<Mx:Form>
<Mx:Label text="Hello world"/>
</Mx:Form>
</Mx:Application>
Can any body please let me know how can i access this Form's Label , from an ActionScript class .
catch(error:*)
// Here i want to access these Objects and set data to that Label .
Basically My requirement is that iinside the catch block of my ActionScript class , i want to set some text to the Label , Please
let me know if this is possible or not also ??
Waiting for your Replies .Hi these both are not same these refer to different one...
Well let me explain...
Application.application.myCustomComp.myLabel.text = "sometext"; sets the label "myLabel" which is present inside your customcomponent(which is in main application).
Application.application.myLabel.text = "sometext"; sets the label "myLabel" which is present directly inside your main application.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Label id="myLabel" text=""/> // So inorder to set the label(myLabel) present here you will use directly the 2nd line of code.
<mx:CustomComp id="myCustomComp" /> // So inorder to set the label(myLabel) present inside this component you use 1st line of code.
</mx:Application>
Hope now its clear.
If this post answers your question or helps, please kindly mark it as such.
Thanks,
Bhasker Chari -
Converting MXML Components to ActionScript Classes
I'm in the process of converting most (if not all) of my MXML
components to Action Script classes. I've found this is easy, and
doesn't require a lot of extra code when extending a simple
container or control. However, several of my MXML components have
several nested containers and controls - i.e. a component that
contains several Labels, a ComboBox, a TextInput, a Button, and a
DataGrid, plus several other containers needed for layout. To code
the layout of all these containers and controls using MXML, it uses
about 16 lines of code. To code the layout in ActionScript, it
takes about 50+ lines of code (see attached).
I'm just wondering if there are any best practices for
creating ActionScript classes that include several (or even A LOT
OF) containers and controls. It's very easy to layout in MXML, and
is more visibly pleasing to look at and understand, but I feel it
is best practice to code components as ActionScript classes. I know
I should be using MVC, but it's a little late to rewrite the entire
application now.
Any thoughts?I can't specifically speak to how to write layout code in
ActionScript, but you can look at the generated code that Flex
creates to get an idea of how Flex does it. When you compile an
app, the Flex compiler takes your MXML input and converts it to
ActionScript classes before compiling the entire set of classes
into a SWF. Because of this, you can look at the interim
ActionScript code.
You do this by setting the keep-generated-actionscript
compiler option to true and looking in the /generated directory.
hth,
matt horn
flex docs -
MXML Components and ActionScript Classes
Hello,
I am fairly new to Flex and OOP and am confused on how some parts of OOP work.
I have a Spark TextInput Component with an id which equals "test".
I also have a function that takes "test.text", appends a string to and and puts the resulting value into another TestInput called test2.
How can I move the "appendPhrase()" function into a class so that it would still accept values from "test" and change the "text2" values?
I tried creating a function that would assign the value of the varaible in the class using classname.variable name, made it bindable, and assigned
the text value of the textinput that value, but I was wondering if there was any other way I could do that?
~~~~~~~~~~~~~~~~Version1~~~~~~~~~~~~~~~~~~~~~
<fx:Script>
private function appendPhrase():void
test2.text = test.text + " was added";
</fx:Script>
<s:TextInput x="0" y="0" id="test" />
<s:TextInput x="0" y="10" id="test2" />
<s:Button click="appendPhrase();" />
~~~~~~~~~~~~~~~~~~Version 2:~~~~~~~~~~~~~~~~~
function in class:
public class ChangeString
[Bindable]
public var text:String;
private function appendPhrase(firstString:Object):void
text = firstString.text + " was added";
main.mxml:
[Bindable]
public var changed:Object = new ChangeString();
<s:TextInput x="0" y="0" id="test" click="changeValue(test.text)" />
<s:TextInput x="0" y="10" id="test2" text="{changed.text}"/>package models
[Bindable]
public class MyViewModel
public var text:String "Hello ";
public function appendText(t:String):String
this.text = this.text + t;
return this.text;
<fx:Script>
<![CDATA[
import models.MyViewModel;
[Bindable]
public var model:MyViewModel = new MyViewModel();
]]>
</fx:Script>
<s:TextInput id="test" x="0" y="0" click="this.model.appendText(this.test.text)" text="World" />
<s:TextInput id="test2" x="0" y="10" text="{this.model.text}" />
I would go about it a little differently maybe. I would use the model class as a data holder, and use a private local method, utility class, or controller class to modify values on the model (data holder class). -
Accessing MXML ArrayCollection from ActionScript class?
I have an MXML file that has an arraycollection for my Tree
component. I am overriding the updateDisplayList function in order
to add lines to all of my nodes in the Tree.. however I can't seem
to figure out how to access that ArrayCollection from inside the
actionscript class?
I have tried the methods used to pass variables between two
MXML files (like a popup window - which I have used in the past and
it works great).
My actionscript class code is almost identical to this
example here:
http://www.iepl.net/treeControlSample/treeControlSample.html
In the above example the data is static, but my data is going
to change sometimes and I need access to the entire dataProvider
(ArrayCollection) in order to make the lines work right.. this has
been very frustrating for me! :)
if anyone knows of a better way to achieve gettign lines to
the siblings in a Tree.. please let me know!
Any help would be super duper awesome!I have found the solution to this. My problem was similar to
the one cheftimo was having in this post:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid =1367784&enterthread=y
The answer is to import mx.core.Application into the
component you are trying to access the variable from and then call
it by using 'Application.application.<var name>'
Thanks to Greg Lafrance! -
Accesing mxml Button from .as file
Hello.
Here's my problem:
1. i've created new extension project
2. in mxml design view, i've added 1 button, and gived it an id of "button"
3. how can i acces that button inside .as file? (i want to add event listeners to it, and change its label);Apparently, the correct way is: FlexGlobals.topLevelApplication
(it seems like FB has some problems with both com.adobe.photoshop.Application and mx.core.Application.application in the same class - at least it fired a bunch of weird errors to me)
Davide -
Updating Swing components from a different class
I would like to use the JTextArea component in a JFrame to display fast updating text from my application. My application is very simple. When the app launches the GUI is created then my application engine would start processing and displaying text data into the GUI. After reading about Thread safety when using Swing components I concluded it would not be a good idea for my app engine class to update the JTextArea class directly using methods such as .append(String).
I would be grateful for any suggestions on how I should approach updating Swing components from different classes.
Many Thanks in advance SeanHi
Why don't you just implement a basic callback method?
To do this the right way you should probably define a simple Interface that has a public method like updateProcessText(String s). Your swing class then implements this interface, basically forcing it to provide the public method you defined (this is no different than implementing ActionListener, which forces you to define actionPerformed). Secondly modify your processing class, so that it take's a class that implements the interface you just created, as one of the arguments in it's constructor. Lastly assign the argument from your construnctor to a private var - this will enable your processing class to have a handle to your swing class and update it as it pleases.
This might sound very complex, but it's really simple once you've done it once. -
Mxml components not compiled into swc?
Hi, I am using Flash Builder(Flex 4) and i am having issues compiling mxml components into swc.
My scenario:
I created Flex Library project, added some mxml components and actionsript classes.
I created separate Flex project and added swc file to project's library path.
I can only import actionscript classes from my library.
ActionScript classes are compiled and bundled in the swc as expected, but all mxml components are not compiled into the swc.
Do you have the same issues compiling mxml components?
I am using Flash Builder Version 4.0 (build 253292).My team occasionally sees issues with missing classes in a similar setup, although I can't confirm that it has been limited to MXML (and no one has been able to reliably reproduce).
I suspect our problem is the "includeAllClasses" property in .flexLibProperties (Project->Properties->Flex Library Build Path->Classes->Include all classes from all source paths)--it seems to not reliably compile in newly added classes. Our workaround right now is to instead click "Select classes to include in the library" and toggle our source directory every time classes are added, at least until we script our own build tasks. Looking through Jira I see this is a common issue: https://bugs.adobe.com/jira/browse/FB-23514 (and a few others).
Hope this helps, -
Accesing from other classes to protected void
Hy! I'm a newbie to java programming. So i am making a program in J2ME, and the problem is :
I have an abstract class, wich i must extend. That class defines a procedure
abstract protected void destroyApp(boolean unconditional), so in my extended class this void is protected. But i want to access to this procedure from other class, and do it somehow static.
I have made a main program class (the extended class), and i want to send from other class a destroy message to it (to call destroyApp procedure).
Kazhha.Your question has nothing to do with Native Methods.
In the future, for novice questions, use the New To Java Technology forum.
I have an abstract class, which i must extend. That
class defines a procedure
abstract protected void destroyApp(boolean
unconditional), so in my extended class this void is
protected.You can make the method public in your class.
But i want to access to this procedure
from other class, and do it somehow static.IIRC you cannot make a method static if it is not static in the class you extend.
I have made a main program class (the extended class),
and i want to send from other class a destroy message
to it (to call destroyApp procedure).Huh? -
Accesing components of global class in another global class.
Hi,
I am not able to access Public TYPES defined on a class in other class.
Class cl_business_object : has public type tt_records type table of <ztable> with default key.
and when i use it in method of cl_gui , get_records returning rt_records type cl_business_object=>tt_records after making the statement of Class definition cl_business_object load / entering the name of the class in properties tab's .. why does it happen ?
Regards.Hi, Its ECC 6.0,
We did nto have this problem before, Its kind of new, have no idea why it behaves so ..
And the syntax error is not generated when we are cheking onthe class where it has been used (acessing other class types) , this is activated.
but another 3rd class where this activated class is used, throw up syntactical error showing error in class 2.
" saying components of global class are not accesible, class definition missing"..
but there are statements of class definition load already!!
Regards
Edited by: Trivvka on Aug 11, 2009 5:06 PM -
Struts - Data pass from Action class to JSP
hello ,
I am new to struts and have a strange question in my mind .
How do we pass business logic data from action class to JSP.Do we use session object or any other best way to be used to pass data.
Example scenario:
Once the user logins into application by passing userid and password ,we need to display his open queries (from database table) on jsp.
Components used :
Login.jsp
LoginForm(getter and setter methods of userid & password)
LoginAction(get database connection,perform query to fetch user's open queries form the database)
OpenQueries.jsp(to display Open queries on a tabular format)
In LoginAction - We fetched user's open Queries from the database and stored them in collection object .
My question is : what is the best way to pass Collection object from LoginAction to OpenQueries.jsp ?
Thanks in advance...
Ram
Edited by: ram_76uk on Apr 10, 2008 8:21 PMYou can use plain javabeans to transfer the data. Check out the jsp:usebean tag. If you don't know how to do, check out the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/ Using javabeans in JSP pages starts halfway chapter 4.
-
Using salesforce connector in multiple mxml components
I am using Flex 2.0.1 and Salesforce as Database. My question
is i am creating login method in each component and application. I
want to use/pass salesforce connection from main application to all
sub component, how can i achieve this to avoid login for each
application/ component.
example: In my project i created main.mxml application and 3
mxml components in each component i am logining into the salesforce
database to retrieve data from the database. i want to avoid
creating multiple logins for the components instead of writing
login for each mxml component i want login for the first time in
main.mxml application and want to use the same connection in mxml
components. Can anyone tell me how can i achieve this
If you feel this is not sufficient information to solve this
problem then let me know i will post another message with sample
code.
Thanks in advance.The solution I ended up using was just to reference the CSS file at the root MXML application. Then I could just use .styleName on the Menu component and voila, it worked.
-
Anyway to make MXML components static?
This isn't too important because I know how to do it well enough in ActionScript. But I like the readability and convenience of MXML components, so if anyone knows if there is a way to make them static, please let me know.
As best I understand it, there is no way to creation Static Classes in ActionScript 3 or MXML:
Class Modifier keywords are dynamic, final, internal, and public.
http://livedocs.adobe.com/flex/3/html/help.html?content=04_OO_Programming_06.html
The Static keyword is only for variables, constants, or methods:
http://livedocs.adobe.com/flex/3/langref/statements.html#static
If you want to create static variables, constants, or methods inside an MXML File do it in a script block, which is the same way you do it in an ActionScript 3 file. -
Dynamically add custom MXML components in Actionscript
As there's no constructor for custom MXML components, how to
dynamically add it as a child using ActionScript?
I'm looking for some alternative to avoid the need to rewrite
the entire existent component in ActionScript just to add it this
feature (a constructor). PopManager is not an alternative...
Is there any way?
The case/situation:
I have a custom MXML component that needs to be dinamically
added to a NativeWindow created using ActionScript.
Thanks a lot!
Vicente Junior
Independent Web Developer
http://teclandoalto.blogspot.commxml classes get generated into AS classes with a default
constructor.
In fact, there is essentially no difference between an AS
component and an mxml component, they can be used exactly the same
way.
Tracy -
OOABAP-How to access the protected methos from a class
How to access the protected methos from a class..There is a built in class..For tht class i have created a object..
Built in class name : CL_GUI_TEXTEDIT
method : LIMIT_TEXT.
How to access this..help me with codehi,
If inheritance is used properly, it provides a significantly better structure, as common components only
need to be stored once centrally (in the superclass) and are then automatically available to subclasses.
Subclasses also profit immediately from changes (although the changes can also render them invalid!).
Inheritance provides very strong links between the superclass and the subclass. The subclass must
possess detailed knowledge of the implementation of the superclass, particularly for redefinition, but also in
order to use inherited components.
Even if, technically, the superclass does not know its subclasses, the
subclass often makes additional requirements of the superclass, for example, because a subclass needs
certain protected components or because implementation details in the superclass need to be changed in
the subclass in order to redefine methods.
The basic reason is that the developer of a (super)class cannot
normally predict all the requirements that subclasses will later need to make of the superclass.
Inheritance provides an extension of the visibility concept: there are protected components. The visibility of
these components lies between that of the public components (visible to all users, all subclasses, and the class itself), and private (visible only to the class itself). Protected components are visible to and can be used by all subclasses and the class itself.
Subclasses cannot access the private components particularly attributes) of the superclass. Private
components are genuinely private. This is particularly important if a (super)class needs to make local
enhancements to handle errors: it can use private components to do this without knowing or invalidating
subclasses.
Create your class inse24 and inherit this CL_GUI_TEXTEDIT
class in yours. You can then access the protected methods.
Hope this is helpful, <REMOVED BY MODERATOR>
Edited by: Runal Singh on Feb 8, 2008 1:08 PM
Edited by: Alvaro Tejada Galindo on Feb 19, 2008 2:19 PM
Maybe you are looking for
-
HT201250 how do i add external hard drive to my time machine back up
how do i add external hard drive to my time machine back up so that I may view the files independently on apple tv please?
-
Buttons in ALV Grid cell need focus to be clicked :-(
Hi, I have an ALV Grid with single cells displayed as buttons (dependend on the data in the corresponding row). Unfortunatelly the button-cells need focus to be clicked. So you need two clicks: one to get the focus to the desired cell and one to real
-
This may be a stupid question, but can I plug my vision+ box into a tv with built-in freeview and still get all my on demand stuff? Solved! Go to Solution.
-
Show Hide transient attribute making row dirty
Hi All I am using an advanced table where one of the columns(Description) is shown in detail region. To implement detail region, we need a transient attribute on the VO. I was able to get everything working. But I have the following problem. When the
-
Adding 50 States to Form Field
Is there an wasy way to input the 50 states into a form field? Or do I have to manually input each state individually? (I'm using Spry Widgets if that means anything...)