Loading MXML Component Dynamically
Hi all,
I am new to Flex and was trying out small things . I created
a MXML Application and also MXML components.
I tried loading MXML component to application using xmlns and
it worked fine.(
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" backgroundColor="#ffffff" xmlns:mi="com.*">
<mi:base1 id="base1" />
<mi:base2 id="base2" />
This method is ok if we are loading 3-4 components .
but , if i have to load a mxml component dynamically how do I
do it?
for example ,if base1 and base2 are two components and i want
to load them based on some event performed.
I have tried the method which uses ViewStack and code
myViewStack.selectedChild=Container(myViewStack.getChildByName(selectedNode))
,where each child will have one component declared or initialized.
Following this method is not a feasible when we have hundred
of components to be loaded.
Can anyone help me on this??
"srirama.83" <[email protected]> wrote in
message
news:gpkoui$g3u$[email protected]..
> Hi all,
> I am new to Flex and was trying out small things . I
created a MXML
> Application and also MXML components.
> I tried loading MXML component to application using
xmlns and it worked
> fine.(
> <mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
> layout="absolute"
> backgroundColor="#ffffff" xmlns:mi="com.*">
> <mi:base1 id="base1" />
> <mi:base2 id="base2" />
> )
> This method is ok if we are loading 3-4 components .
> but , if i have to load a mxml component dynamically how
do I do it?
> for example ,if base1 and base2 are two components and i
want to load them
> based on some event performed.
>
> I have tried the method which uses ViewStack and code
>
myViewStack.selectedChild=Container(myViewStack.getChildByName(selectedNode))
> ,where each child will have one component declared or
initialized.
>
> Following this method is not a feasible when we have
hundred of components
> to
> be loaded.
> Can anyone help me on this??
>
>
http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
Q4
Similar Messages
-
Loading an "MXML Component" at run-time creates a null object.
Hello!
I have a simple Flex 3 project with an MXML application file (the parent) and an MXML component file (the child).
At run-time I create childs of this component, and I add it to the stage using a simple "this.addChild()" call.
Now, besides that, in the creation loop, after every
newChild = new mcComp();
I want to setup a few more custom parameters which belongs to this class. For example, now I want to set a label's text, this label is at the child.
The issue is that the label isn't created until I exit the creation function, and actually, until my code returns control to the Flash Player.
See my problem here?
With custom classes which resides at .AS files, when I instantiate them with the "new" operator, they run their constructure's code and eveything is fine.
But, when I do the same with those MXML components (which by the way are based over the Canvas class), their constructure do not execute and actually no other child of them is created.
Can anyone please advise? I must be missing some keyword here.. hopefully.Hi Natasha thanks,
The issue is that the creationComplete event doesn't dispatch even when I addChild() the object.
var child:mcChild = null;
for(var i:int; i < 3; i++)
child = new mcChild();
// setting some properties, labels' text etc'
this.addChild(child);
Try this and you'll see - the event doesn't dispatch until you got out of the code flow.
Anyway after looking at Flex's documentation I solved it differently;
After the addChild() call the child receives an "initialize" event. After that I could modify my label.
Thank you though! -
Dynamic addition of MXML Component
Is it possible to add an MXML component through an ActionScript.
I have a situation where I display multiple checkboxes and on click of each I show a subform. I am planning to make that subform as MXML component and add/remove it based on the user's checking/unchecking the checkbox..Is this possible?
Thanks
DharmeshHi Ben ..
Appreciate your quick response. This is my first Flex app. In a nut sheel here is a sample similar to what I am trying to achieve.
Consider my Mxml component as follows
<?xml version="1.0" encoding="utf-8"?>
<!-- myComponents/TempComponent.mxml -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:Button label="Hey there from component"/>
</mx:Canvas>
Now here he my app mxml file
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:temp="mycomponents.*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function addRemove():void{
//How do i add that component to the Panel?
]]>
</mx:Script>
<mx:Checkbox id="cb" change="addRemove()" label="Check or Uncheck"/>
<mx:Panel id="testPanel" x="0" y="0" width="100%" height="200" layout="absolute" borderThickness="0" borderThicknessBottom="0"/>
Can you guide me what should go in the listener to add the component to the panel? -
MXML Component Child Objects Loaded?
I have a MXML component with various child components within. My question is:
Are the child components initiated when the MXML component is initialized in AS (i.e. var instance:MyComponent = new MyComponent();)?
The reason I'm asking this is because the child components are null after the component is initialized in AS when stepping through with the debugger.
Thanks!
MikeSee creationPolicy, createChildren and references to deferred instantiation in the doc. Children are not created in the constructor for performance reasons.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.
Blog: http://blogs.adobe.com/aharui -
Help cant get photos to appear with advanced loader pro component
Im tryign to make a portfolio site Trying to use the Advanced loader pro component to get the photos to appear. I am following the instructions here
file:///C:/Users/User/Desktop/Tutorials/Flash%20plug%20in%20instructions/Advanced%20Loade r%20PRO%201.0.1/Guide/index.html
But nothign is happening when I test locally using pubish preview or online when uploaded.
This is whats in my component paramters in properties
Autofeeder file - autofeeder.php
c:\users\me\documents\website\test folder\autofeeder.php
Autofeeder folder is the image folder in the folder with the swf files.
c:\users\me\documents\website\test folder\images
in test folder as the swf files, autofeeder.php file and images folder containing the images to show
The swf file is.
aboutme.swf
in Image folder
sketch1.jpg
sketch2.jpg
sketch3.jpg
under source for the values
sketch1.jpg
sketch2.jpg
sketch3.jpg
under caption
caption1
caption2
caption3
Picking random effects (just want it working so have 2 wipes
effect strenght8
effect speed 44
showtime 15
captionTextfield
the same name as my dynamic text box instance
captionTextfield
scale content = scale to fit
on rollover zoom 100%
Show pre loder is ticked and show preload
pre loader width 100
target _blank
enabled
visible
Please what am I missing here who no photos as need this to get work
And min height and width 500
Please what am I missing here who no photos as need this to get work
his is rough as just trying to get it to work yet I see no picture/photos on the stag with the component and nothign when I try a flash preview locally on computer or publishtest movie...
What am I doing wrong why no pictures pleaseNever mind I got it working right my photos are appearing now.
-
Optimizing mxml component having so many group
Hi,
I am stuck in critical issue which I have to fix within today. I have a view component or mxml component having 50 group.
After slashscreen Its taking too much time and memory to load first view and GUI stuck for few minutes.
There is any solution of this issue.I want to queued all group creation according to requirement I want to load it.
If there is any alternate way then it will be helpful to me,
Any help will be appreciated,I was going to look at the code for your Groups to see if I could suggest a quick way of refactoring the app to not all get instantiated at once.
Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui -
Very simple library with one MXML component ERROR
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
mouseDown="FlexGlobals.topLevelApplication.nativeWindow.startMove()"
width="350" height="42" top="0" left="0" right="0">
<s:states>
<mx:State name="maxed"/>
<mx:State name="restored"/>
</s:states>
<fx:Script>
<![CDATA[
import flash.events.MouseEvent;
import mx.core.FlexGlobals;
private var maxed:Boolean = false;
private function restore(e:MouseEvent):void{
if (maxed){
FlexGlobals.topLevelApplication.restore();
this.currentState = "restored";
maxed = false;
}else{
FlexGlobals.topLevelApplication.maximize();
this.currentState = "maxed";
maxed = true;
public function Maximize() : void
if (this.maxed)
FlexGlobals.topLevelApplication.restore();
this.currentState = "restored";
this.maxed = false;
else
FlexGlobals.topLevelApplication.maximize();
this.currentState = "maxed";
this.maxed = true;
return;
}// end function
public function get Maximized():Boolean{
return this.maxed;
]]>
</fx:Script>
<s:Rect left="0" top="0" bottom="0" right="0">
<s:fill>
<s:SolidColor color="#FFFFFF"/>
</s:fill>
</s:Rect>
<s:Image x="5" y="-4" source="assets/colibright_title.png" left="5"/>
<s:Button y="10" width="32" height="32" click="FlexGlobals.topLevelApplication.minimize();" icon="assets/icons/minimize.png" y.restored="5" y.maxed="5" right.restored="74" right.maxed="74"/>
<s:Button width="32" height="32" click="restore(event)" y="5" icon="assets/icons/restore.png" includeIn="maxed" right="39"/>
<s:Button y="5" click="restore(event)" includeIn="restored" width="32" height="32" icon="assets/icons/maximize.png" right="39"/>
<s:Button y="10" width="32" height="32" click="FlexGlobals.topLevelApplication.close();" icon="assets/icons/close.png" y.restored="5" y.maxed="5" right.restored="5" right.maxed="5"/>
</s:Group>
In my main application when i try to load the SWF and use the Custom MXML Component i get this error
[SWF] C:\Users\dude\Adobe Flash Builder 4.7\Colibr8\bin-debug\extensions\00 - WindowControlUIPlugin.swf - 8,287 bytes after decompression
VerifyError: Error #1014: Class spark.components::Group could not be found.
private function launchPluginsInspection():void{
plLoader = new Loader();
plLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPluginLoaded);
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
context.allowLoadBytesCodeExecution = true;
context.allowCodeImport = true;
var appFolder:File = File.applicationDirectory;
var extensionsFolder:File = new File(appFolder.nativePath + "/extensions/");
if (extensionsFolder.isDirectory){
var files:Array = extensionsFolder.getDirectoryListing();
for each(var file:File in files){
if (file.extension == "swf")
plLoader.load(new URLRequest(file.nativePath), context);
Why is this happening?Can you try giving permissions for the player to access your swf file by adding this
Security.allowDomain( '<Location of the swf file>' );
or
System.security.allowDomain( '<location of the swf file>' );
Thanks,
Sudhir -
UIScrollBar component dynamic text capital letter Y not appearing
I'm using the UIScrollBar component, dynamic text is my setting. When I view the swf or exe, all my text appears except for capital letter Y, it appears in flash, but not the swf or exe file.
Any reason why this happens?
Any help is appreciated.I finally found the answer but this scenario doesn't make
sense. It seems you have to create a dynamic text field with a
scrollbar during runtime through actionscript, rather then creating
the text field and scrollbar in design mode. Here is the code that
worked:
import fl.controls.UIScrollBar;
var myTxt:TextField = new TextField();
myTxt.background = true;
myTxt.backgroundColor = 0xFFFFFF;
myTxt.border = true;
myTxt.wordWrap = true;
myTxt.width = 200;
myTxt.height = 200;
myTxt.x = 22;
myTxt.y = 75;
var mySb:UIScrollBar = new UIScrollBar();
mySb.direction = "vertical";
// Size it to match the text field.
mySb.setSize(myTxt.width, myTxt.height);
// Move it immediately right the text field.
mySb.move(myTxt.x + myTxt.width, myTxt.y);
// put them on the Stage
addChild(myTxt);
addChild(mySb);
// load text
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("breakroomText.txt");
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadcomplete);
function loadcomplete(event:Event) {
// move loaded text to text field
myTxt.htmlText = loader.data;
// Set myTxt as target for scroll bar.
mySb.scrollTarget = myTxt; -
I have two Major issues with our Infinity Project computers,
We have one entire lab that is getting this error... "Unable to load
block component C:\Program Files\Hyperception\VABINF\KeyRcv.dll.
Please verify that the component exists and any dependencies it may
have are satisfied." It is also producing this error with
NumEntry.dll. Both files exist. I am not sure what
dependencies these files may have. Ideas?
We have several systems that are giving the following error on one of
our labs... "You have exceeded the number of block functions allowed by
VAB for Infinity; contact Hyperception regarding upgrades." From
what The professor here at UTA told me when I first took on this
project, this was a problem that we had on the previous boards and that
someone at Hyperception was able to help us resolve this problem.
Can you help out with these issues? The first one I need an answer today if possible.
Thanks,We have seen this type of problem on some computers (we do not know why as of yet).The problem with missing blocks is very likely being caused by file permissions, and can be seen when non-administrators are using VAB software. To resolve this: 1. login as ADMINISTRATOR 2. run the command line script from a DOS prompt as shown below: cacls "C:\Program FIles\Hyperception\VABINF" /T /E /G Everyone:F It will scroll through the name of every file in the provided directory, and all subdirectories. This should reset every file, and allow the USER to access all files in VAB software. This should correct the problem. Regards,Steve
-
How to Create a Table Component Dynamically based on the Need
Hello all,
I have a problem i need to create dynamically tables based on the no of records in the database. How can i create the table object using java code.
Please help.Winston's blog will probably be helpful:
How to create a table component dynamically:
http://blogs.sun.com/roller/page/winston?entry=creating_dynamic_table
Adding components to a dynamically created table
http://blogs.sun.com/roller/page/winston?entry=dynamic_button_table
Lark
Creator Team -
How to load a Class Dynamically?
hi,
I have the following problem.I am trying to load a class dynamically.For this I am using ClassLoader and its Loadclass method.My code is like this,
File file = filechooser.getSelectedFile();
ClassLoader Cload = this.getClass().getClassLoader();
String tempClsname= file.getName();
Class cd =Cload.loadClass(tempClsname);
Object ob =(Object)cd.newInstance();
showMethods(ob);
In showMethods what i am doing is getting the public methods of the dynamically loaded class,
void showMethods(Object o){
Class c = o.getClass();
System.out.println(c.getName());
vecList = new Vector();
Method theMethods[] = c.getDeclaredMethods();
for (int i = 0; i < theMethods.length; i++) {
if(theMethods.getModifiers()==java.lang.reflect.Modifier.PUBLIC)
String methodString = theMethods.getName();
System.out.println(methodString);
vecList.addElement(methodString);
allmthdlst.setListData(vecList);
Now whenever i work with this i m getting a runtime error of CLASS NOT FOUND Exception..I know its because of Classpath..But i don't know how to resolve it??pls help me in this regard...
Also previously this code was working with java files in the directory in which this java file was present..How to make it work for java file in some other directory..pls help me in this regard...
Thanks in advance..You sure didn't need to post this twice.
http://forum.java.sun.com/thread.jsp?thread=522234&forum=31&message=2498659
When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read and prevents accidental markup from array indices like [i].
You resolve this problem by ensuring the class is in the classpath and you refer to it by its full name.
§ -
How to load a class dynamically and then a call a method?
Hi
I want to call a method from a class,which class is loaded dynamically.
Consider a classA and ClassB..
ClassB contains a method showvalue() which returns a String value.
I want to load a ClassB dynamically in ClassA,and call the method showvalue() and print the returned value of that method (showvalue).
How to do this?
ThanksSince you found your way to Reflections and Reference Objects, I can only assume you know that reflection is the answer. Since the reflection tutorial on this site, and indeed, the many others on the web, can explain this a whole lot better and more consisely than can be done in a forum, I'll point you in that direction instead. As a starting point, and to show I'm not just fobbing you off, you're interested in the classes java.lang.Class, java.lang.reflect.Method, and the method Class.getMethod(String, Class[])
-
Interface not found in implements-attribute for MXML component
Hi,
I am trying to use the "implements" attribute for an
MXML-component in order to implement an interface from a library
like below (Flex 3). I get the error "Interface IClonable not
found". The compiler does not complain about " import
com.yworks.support.IClonable;", so the library is installed
correctly. I use the library in many places in my project, it just
does not find it in the "implements" tag. How can I fix this
without reimplementing the component in ActionScript?
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
implements="com.yworks.support.IClonable">
<mx:Script>
<![CDATA[
import com.yworks.support.IClonable;
]]>
</mx:Script>
</mx:VBox>"mavdzee" <[email protected]> wrote in
message
news:gldjg8$js8$[email protected]..
> Hi,
>
> I am trying to use the "implements" attribute for an
MXML-component in
> order
> to implement an interface from a library like below
(Flex 3). I get the
> error
> "Interface IClonable not found". The compiler does not
complain about "
> import
> com.yworks.support.IClonable;", so the library is
installed correctly. I
> use
> the library in many places in my project, it just does
not find it in the
> "implements" tag. How can I fix this without
reimplementing the component
> in
> ActionScript?
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
> implements="com.yworks.support.IClonable">
>
> <mx:Script>
> <![CDATA[
>
> import com.yworks.support.IClonable;
>
> ]]>
> </mx:Script>
>
> </mx:VBox>
I don't see anything where you're actually _implementing_ the
interface, but
I'd expect to see a different error if that's the problem.
Still, I'd go
ahead and implement the properties and methods in the
interface, just to
make sure.
HTH;
Amy -
Event Fired when a mxml component is shown on screen
hello,
I have following application structure nested up to 2/3 level.
Application
linkbar connected to viewstack
viewstack
NavigatorContent
mxml Component
NavigatorContent
mxml Component
mxml componet in turn has similar structure
componet
linkbar connected to viewstack
viewstack
NavigatorContent
mxml Component
NavigatorContent
mxml Component
and end component is form which is shown and actions performed
I want to execute specific code when the form is first time shown
which will collect data from server and will show for further actions.
User will edit/delete/update data with various button clicks.
I tried activate event on end component but it seems that it wont get
fired at all. End components are enclosed in BorderContainer or Group.
To test activate event I have used Alert.show only but popup is not shown
when I select link button on penutimate linkbar.
If I am doing something wrong please let me know as well please
guide me which event shall I use so that whenever linkbutton is
pressed on linkbar it will fire that event. In that event I can check
whether it has been called earlier by checking some variable which
will be null in creation complete and set in event fired when linkbutton is pressed.
Thanks and regards
RajaI think 'creationComplete' is the closest event to what you are looking for.
-
Load JDBC-Driver dynamically with JarClassLoader
Hey!
I have a problem loading JDBC drivers dynamically with a JarClassLoader:
Code:
public class URLLoaderTest {
public static void main(String[] args) {
try {
URL[] urlList = {new File("D:\\jbuilder5\\SQLServerJDBC\\lib\\mssqlserver.jar").toURL(),
new File("D:\\jbuilder5\\SQLServerJDBC\\lib\\msbase.jar").toURL(),
new File("D:\\jbuilder5\\SQLServerJDBC\\lib\\msutil.jar").toURL()};
ClassLoader classLoader = new URLClassLoader(urlList);
Class c = Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver",true,classLoader);
Object d = c.newInstance();
DriverManager.registerDriver((Driver)d);
// DriverManager.getDrivers() Enumeration is empty
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://Server:1433","test","test");
DatabaseMetaData meta = conn.getMetaData();
System.out.println("JDBC driver version is " + meta.getDriverVersion());
catch (Exception e) {System.out.println(e.getMessage());}
}Problem:
Till the DriverManager registraton everything is ok.
The registerDriver Method throws no exception but if I call DriverManager.getDrivers() after calling the registerDriver Method an empty Enumeration is returned.
So the driver is not loaded and DriverManager.getConnection throws an Exception (no suitable driver).
If I include the driver jars into the Classpath everything is running (but that isn't what I want to do).
Is there a solution for this problem? Maybe it is possible to load the data into the AppClassLoader??!!
Thanx in advance.Found a solution!
For everyone who is interested:
public class URLLoaderTest {
public static void main(String[] args) {
try {
URL[] urlList = {new File("D:\\jbuilder5\\SQLServerJDBC\\lib\\mssqlserver.jar").toURL(),
new File("D:\\jbuilder5\\SQLServerJDBC\\lib\\msbase.jar").toURL(),
new File("D:\\jbuilder5\\SQLServerJDBC\\lib\\msutil.jar").toURL()};
ClassLoader classLoader = new URLClassLoader(urlList);
Class c = Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver",true,classLoader);
Object d = c.newInstance();
Driver driver = (Driver)d;
Properties prop = new Properties();
prop.setProperty("user","test");
prop.setProperty("password" ,"test");
Connection conn = driver.connect("jdbc:microsoft:sqlserver://test:1433",prop);
System.out.println("JDBC driver version is " + meta.getDriverVersion());
catch (Exception e) {System.out.println(e.getMessage());}
}
Maybe you are looking for
-
Watch movie on Mac rented via TV
Yesterday I rented a movie via TV. Now I want to watch it again on my Mac. Do I need to rent it again in iTunes? (I don't want to pay twice, so I ask before trying.) Thank you!
-
I've been using Amazon MP3 to download music onto my Blackberry Curve 9320 for a few months. Now for some reason it won't let me download anything. Comes up with the error message 'your order could not be processed'. If I go into Amazon and check the
-
There is supposed to be a new 1 TB LUN attached to an Oracle server but it doesn't seem to show up. I've tried the usual commands like cfgadm and format but without any luck. The guy who allocates stuff on the EMC tells me (I am not sure what it mea
-
I'm begginer in Java2. I got books to study but they don't include practical exercises or assignments. I find it easy to work through the topics if you do some practical work. Where can I find materials to study that include all of this? Thanks in ad
-
How do i watch a wmv file on my imac
OS X Lion 10.7.4