Flex Actionscript call parent function - actionscript-3

I have an actionscript file in my flex project. I loaded the actionscript into flex via addElement()
MXML File:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
public var sv:Myastest;
protected function init(event:FlexEvent):void
{
sv = new Myastest();
addElement(sv);
sv.classfunc();
}
public function mainfunc():void
{
trace("mainfunc called");
}
]]>
</fx:Script>
</s:WindowedApplication>
ActionScript File:
package
{
import flash.events.Event;
import mx.core.UIComponent;
[SWF(frameRate="25", backgroundColor="#000000")]
public class Myastest extends UIComponent
{
public function Myastest()
{
trace("loaded..");
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void
{
trace("added to stage");
}
public function classfunc():void
{
trace("classfunc called");
}
}
}
How can I call mainfunc() from the actionscript file? Thank you.

IN THE CLASSMANAGEREVENT
public class ManagerEvent
{
public static const EVENT_MAIN_CLASS_FUNC:String = UIDUtil.createUID();
FlexGlobals.topLevelApplication.addEventListener(EVENT_MAIN_CLASS_FUNC, executeMainClassFuncCommand)
public function executeMainClassFuncCommand(event:MainClassFunc):void
{
var cmd:FUNCTIONCommand = new FUNCTCommand();
cmd.execute(event);
}
}
CLASS EVENT
public class MainClassFunc extends Event
{
public function MainClassFunc()
{
super(ManagerEvent.EVENT_MAIN_CLASS_FUNC);
}
}
IN THE CHILD
var mainClassFunc:MainClassFunc = new MainClassFunc();
FlexGlobals.topLevelApplication.dispatchEvent(mainClassFunc);

To expand on RIAStar's comment, you could do this:
MXML File:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
public var sv:Myastest;
protected function init(event:FlexEvent):void
{
sv = new Myastest();
sv.addEventListener(Myastest.EVENT_NAME, mainfunc);
addElement(sv);
sv.classfunc();
}
public function mainfunc(e:Event):void
{
trace("mainfunc called");
}
]]>
</fx:Script>
</s:WindowedApplication>
ActionScript File:
package
{
import flash.events.Event;
import mx.core.UIComponent;
[SWF(frameRate="25", backgroundColor="#000000")]
public class Myastest extends UIComponent
{
public static const EVENT_NAME:String = "EVENT_NAME";
public function Myastest()
{
trace("loaded..");
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void
{
trace("added to stage");
}
public function classfunc():void
{
trace("classfunc called");
//assuming you want the mainfunc to get called from here
dispatchEvent(new Event(EVENT_NAME));
}
}
}
Please note that you need to call removeEventListener before you set sv = null.

Related

Actionscript Event Error

I try to dispatch event from actionscript class. But I get the error: "Error #1034: Type Coercion failed: cannot convert flash.events::Event#9f849c1 to mx.events.FlexEvent."
Here is my code:
MXML Code:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init(event)">
<fx:Script>
<![CDATA[
import com.testing.package.MyASClass;
import mx.events.FlexEvent;
public var sv:MyASClass;
protected function init(event:FlexEvent):void
{
sv = new MyASClass();
sv.addEventListener("myevent",mainfunc);
sv.myfunc();
}
protected function mainfunc(event:FlexEvent):void
{
trace("receive event");
}
]]>
</fx:Script>
</s:WindowedApplication>
Actionscript file:
package com.testing.package
{
import flash.display.Sprite;
import flash.events.Event;
public class MyASClass extends Sprite
{
public function MyASClass()
{
}
public function myfunc():void
{
dispatch();
}
private function dispatch():void
{
dispatchEvent(new Event("myevent"));
}
}
}
Why the error occur? How can I fix it?
Thank you.
//Solution is need replace FlexEvent into Event
protected function mainfunc(event:Event):void{
trace("receive event");
}

Create Custom Dialog Box using dispatch events,states and titlewindow in flex/AS3.0

Since a month Iam working on creating a custom dialog box, having parameters like message,state and modal(true/false)
Eg:
showAlert("Hi, how are you doing","Goodmorning", true);
I have learned how to dispatch event. but unable to dispatch the alertevent/popupManager using States.
Below is the code, I am struggling with.
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function onclick(event:MouseEvent):void
{
this.dispatchEvent("Hi, How are you?", "Morning", true);
}
public function dispatchEvent(arg1:String, arg2:String, arg3:Boolean):void
{
var str:*=null;
str.message = arg1;
str.stateName = arg2;
str.modal = arg3;
this.dispatchEvent(new ShowAlert(ShowAlert.SHOW, true));
}
]]>
</mx:Script>
<mx:Button id="click" click="onclick(event)"/>
</mx:Application>
ShowAlert.as
package
{
import flash.events.*;
public class ShowAlert extends Event
{
public var _stateName:String;
public var _closable:Boolean;
public var _message:String;
public var _isModal:Boolean;
public static const SHOW:String="show";
public function flash.events.(arg1:String, arg2:Boolean=false, arg3:Boolean=false)
{
super(arg1, arg2, arg3);
trace("arg1: "+arg1+"\t arg2: "+arg2+"\t arg3: "+arg3);
}
public function set message(arg1:String):void
{
this._message = arg1;
}
public function get message():String
{
return _message;
}
public function get modal():Boolean
{
return _isModal;
}
public function get stateName():String
{
return _stateName;
}
public function set stateName(arg1:String):void
{
this._stateName = arg1;
}
public function set modal(arg1:Boolean):void
{
this._isModal = arg1;
}
public override function clone():flash.events.Event
{
return new ShowAlert(type);
}
}
}
I was unable to write the custom titlewindow using states, so I dint post that.
Please let me know, how to make this happen.
Below is the Sample code, specifying my problem
main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public var info:IModuleInfo;
public var loadalert:DisplayObject;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;
import mx.events.ModuleEvent;
public function init():void
{
Alert.show("This is forst alert.");
}
public function Loadalerrt():void
{
trace("loadalertmodule");
info = ModuleManager.getModule("../bin-debug/alerrtmod.swf");
info.addEventListener(ModuleEvent.READY, modEventHandler);
info.load();
}
public function modEventHandler(event:ModuleEvent):void
{
trace("modeventHandler");
loadalert=info.factory.create() as DisplayObject;
can1.addChild(loadalert);
}
]]>
</mx:Script>
<mx:Button label="Alert in Application" id="b1" click="init()" x="29" y="21"/>
<mx:Button label="Load Module" id="b2" click="Loadalerrt();" x="10" y="92"/>
<mx:Canvas id="can1" x="409" y="57" backgroundColor="cyan"/>
</mx:Application>
alerttmod.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function alertshow():void
{
Alert.show("This is second alert, You Can see it covers whole application, What I want is its scope should be limited to this specific module, not to whole application ");
}
]]>
</mx:Script>
<mx:Button label="Alert in Module" id="b1" click="alertshow()" x="163" y="100"/>
</mx:Module>
Now I see your problem. I think it is not possible to restrict the modal area of the Alert. I can suggest you to fake the modal behaviour by desabling the modules elements while your dialog is being shown.
May be it can help you...
Here are two components to demonstrate it:
//your module with another Alert
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;
public function alertshow():void
{
Alert.show("This is second alert...");
}
public function alertshow2():void
{
var customAlert:CustomAlert = new CustomAlert();
customAlert.addEventListener("CLOSED", onCustomAlertClosed);
this.enabled = false;
PopUpManager.addPopUp(customAlert, this, false);
PopUpManager.centerPopUp(customAlert);
}
private function onCustomAlertClosed(evt:Event):void
{
this.enabled = true;
}
]]>
</mx:Script>
<mx:Button label="Alert in Module" id="b1" click="alertshow()" x="163" y="100"/>
<mx:Button label="CustomAlert in Module" id="b2" click="alertshow2()" x="163" y="150"/>
<mx:Canvas width="100%" height="100%" backgroundColor="0xbbbbbb" alpha="0.8" visible="{!this.enabled}"/>
</mx:Module>
//simple CustomAlert as a Panel
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="300" height="200">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
protected function button1_clickHandler(event:MouseEvent):void
{
PopUpManager.removePopUp(this);
this.dispatchEvent(new Event("CLOSED"));
}
]]>
</mx:Script>
<mx:Button x="112" y="128" label="Close" click="button1_clickHandler(event)"/>
</mx:Panel>

how to work with event in Flex?

import flash.events.Event;
public class RequestEvent extends Event
{
public static const REQUEST:String = "request";
private var Results:Boolean;
public function get Results():Boolean
{
return _Results;
}
public function RequestEvent(Results:Boolean=false)
{
super(REQUEST);
Results = Results;
}
override public function clone():Event
{
return new RequestEvent(Results);
}
}
}
hi can some body explain why we are doing overridding of function clone and calling super(request), new in flex ........so don't mind.
One needs to implement the clone method just so that Flex could re-clone the event in the case when an event handler wishes to dispatch the same event again. Flex does provide a default implementation but one may override the method to clone the event differently, if need be.
As for calling the super method, you must call the super becasue you are extending the Event class. The type (in your case, REQUEST) must be a unique string that would uniquely identify the event to Flex platform.
Hope it helps
Regards.
The question about the overriding of the clone method in custom events is very popular and it seems to be one of the Flex strange things. You can read about it here.
So you have to override this method and only in this method you can define values of custom properties. The method is not usual, so if you try to debug it you will never get the debugger in its body.
If you try to define the value of your custom property in the constructor, the value will be ignorred.
It can be unpractical to use a constant string as the event's type value. In this case all instances of your RequestEvent are of the same type and you could not tell them appart using in different situations. As you can see in the example below, this string is used in action listener to map the listener function.
In this example I have three buttons with different events - normal Event, my version of RequestEvent and your version of it. Have a look at it, I hope it can help to understand the case.
//Application
<fx:Script>
<![CDATA[
import fld02.com.customevent.RequestEvent;
import fld02.com.customevent.RequestEvent2;
import mx.controls.Alert;
private function onCustomGroupBtn2Clicked(evt:RequestEvent):void
{
Alert.show('Btn2Clicked: results = ' + evt.results.toString(), 'This is RequestEvent');
}
private function onCustomGroupBtn3Clicked(evt:RequestEvent2):void
{
Alert.show('Btn3Clicked: Results = ' + evt.Results.toString(), 'This is your RequestEvent');
}
]]>
</fx:Script>
<customevent:CustomGroup
BUTTON1_CLICKED="{Alert.show('Btn1Clicked', 'This is Event')}"
BUTTON2_CLICKED="onCustomGroupBtn2Clicked(event)"
request="onCustomGroupBtn3Clicked(event)"/>
</s:Application>
//CustomGroup
<?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" width="346" height="144">
<fx:Metadata>
[Event(name="BUTTON1_CLICKED", type="flash.events.Event")]
[Event(name="BUTTON2_CLICKED", type="fld02.com.customevent.RequestEvent")]
[Event(name="request", type="fld02.com.customevent.RequestEvent2")]
</fx:Metadata>
<fx:Script>
<![CDATA[
private function onBtn1Click():void
{
this.dispatchEvent(new Event("BUTTON1_CLICKED"));
}
private function onBtn2Click():void
{
var requestEvent:RequestEvent = new RequestEvent("BUTTON2_CLICKED");
requestEvent.results = true;
this.dispatchEvent(requestEvent);
}
]]>
</fx:Script>
<s:Button x="43" y="31" width="183" label="Generate Event" click="onBtn1Click()"/>
<s:Button x="43" y="62" width="183" label="Generate RequestEvent" click="onBtn2Click()"/>
<s:Button x="43" y="93" width="183" label="Generate Your RequestEvent" click="{this.dispatchEvent(new RequestEvent2(true))}"/>
</s:Group>
//My RequestEvent
package fld02.com.customevent
{
import flash.events.Event;
public class RequestEvent extends Event
{
private var _results:Boolean;
public function RequestEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
override public function clone():Event
{
var requestEvent:RequestEvent = new RequestEvent(this.type);
requestEvent.results = this.results;
return requestEvent;
}
public function get results():Boolean
{
return _results;
}
public function set results(value:Boolean):void
{
_results = value;
}
}
}
//Your RequestEvent
package fld02.com.customevent
{
import flash.events.Event;
public class RequestEvent2 extends Event
{
public static const REQUEST:String = "request";
public function RequestEvent2(Results:Boolean=false)
{
super(REQUEST);
Results = Results;
}
private var _Results:Boolean;
public function get Results():Boolean
{
return _Results;
}
override public function clone():Event
{
return new RequestEvent2(Results);
}
}
}

In label, value is not displaying which is used in module

I am trying to call a function (having two parameters) of module and assign values to it.
I can see the value being assigned in trace, but the same value is not displaying when it is assigned to label.
If I directly assign the value to label. It says:
Error:1009: Null object Reference
If I use [Bindable] meta tag to that label, it won't show any runtime error but the value is also not displayed. I have searched the internet and found that the [Bindable] meta tag works as try and catch blog.
How to get value display assign to label?
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:custom="com.custom.*" xmlns:local="*" creationComplete="onload()">
<mx:Script>
<![CDATA[
import modules.AModule;
import mx.events.ModuleEvent;
import mx.containers.VBox;
import mx.containers.TitleWindow;
import mx.controls.TextInput;
import mx.controls.Button;
import mx.containers.HBox;
import mx.controls.Label;
import mx.events.CloseEvent;
import mx.controls.Text;
import com.custom.CustomAlert;
import mx.controls.Alert;
import mx.containers.Canvas;
import mx.events.ItemClickEvent;
import mx.core.UIComponent;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;
import mx.containers.Box;
import mx.controls.ProgressBar;
//private var can:Canvas;
public var titlewin:TitleWindow = new TitleWindow();
public var usern:TextInput = new TextInput();
public var passw:TextInput = new TextInput();
public var vb:VBox = new VBox();
public var hb1:HBox = new HBox();
public var hb2:HBox = new HBox();
public var hb3:HBox = new HBox();
public var nc:NetConnection;
public var bt1:Button = new Button();
private var pb:ProgressBar;
private var progressContainer:Box;
private var info:IModuleInfo;
private var module:UIComponent = null;
public var can:Canvas= new Canvas();
public function onload():void
{
var label1:Label= new Label();
var label2:Label= new Label();
label1.text="Username";
label2.text="Password ";
hb1.addChild(label1);
hb1.addChild(usern);
hb2.addChild(label2);
hb2.addChild(passw);
vb.addChild(hb1);
vb.addChild(hb2);
bt1.label="Sign In";
hb3.addChild(vb);
hb3.addChild(bt1);
titlewin.addChild(hb3);
//Title Window creation starts here
titlewin.title="Login";
titlewin.setStyle("paddingLeft",20);
titlewin.setStyle("paddingRight",20);
titlewin.setStyle("paddingTop",20);
titlewin.setStyle("paddingBottom",20);
titlewin.setStyle("borderThicknessBottom",0);
titlewin.setStyle("borderThicknessLeft",0);
titlewin.setStyle("borderThicknessRight",0);
titlewin.setStyle("borderThicknessTop",0);
titlewin.setStyle("cornerRadius",0);
titlewin.setStyle("borderColor","#D20101");
this.addChild(titlewin);
viewStack.enabled=false;
ctbb.enabled=false;
bt1.addEventListener(MouseEvent.CLICK, netconn);
}
private function onclick():void
{
if(usern.text!="")
{
this.removeChild(titlewin);
viewStack.enabled=true;
ctbb.enabled=true;
username.text=usern.text;
}
else
{
Alert.show("Please enter Username");
}
}
private function netconn(event:MouseEvent):void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/loginhere",usern.text);
nc.addEventListener(NetStatusEvent.NET_STATUS, onstatushandler);
}
private function onstatushandler(event:NetStatusEvent):void
{
if(event.info.code=="NetConnection.Connect.Success")
{
status.text="Connected";
onclick();
}
if(event.info.code=="NetConnection.Connect.Rejected")
{
status.text="Rejected";
}
if(event.info.code=="NetConnection.Connect.Failed")
{
status.text="Failed";
}
}
private function JoinClick(event:MouseEvent):void{
if(viewStack.numChildren==3)
{
Alert.show("You Cant Add More Button","Alert");
}
if(viewStack.numChildren<3)
{
if(viewStack.numChildren<2)
{
can.label="Button2";
var button1:CustomButton= new CustomButton();
button1.label="Leave Table";
button1.x=300;
button1.y=200;
var txt:Text = new Text();
txt.text=can.label;
txt.x=50;
txt.y=50;
button1.addEventListener(MouseEvent.CLICK,remove2);
can.addChild(button1);
can.addChild(txt);
loadmodule();
}
else
{
can.label="Button3";
var button2:CustomButton= new CustomButton();
button2.label="Leave Table";
button2.x=300;
button2.y=200;
button2.addEventListener(MouseEvent.CLICK,remove3);
can.addChild(button2);
var txt1:Text = new Text();
txt1.text=can.label;
txt1.x=50;
txt1.y=50;
can.addChild(txt1);
}
can.setStyle("backgroundColor","0x5EA5BA");
viewStack.addChild(can);
if(viewStack.numChildren>2)
{
viewStack.selectedIndex=2;
}
else
{
viewStack.selectedIndex=1;
}
}
}
private function remove2(event:MouseEvent):void{
Alert.show("Do you want to Leave Table?","Confirmation",Alert.YES|Alert.NO,this,closeAlert2);
}
private function closeAlert2(event:CloseEvent):void{
if(event.detail==Alert.YES)
{
viewStack.removeChildAt(1);
}
}
private function remove3(event:MouseEvent):void{
if(viewStack.numChildren>2)
{
Alert.show("Do You want to leave Table?","Confirmation",Alert.YES|Alert.NO,this,closeAlert3);
}
else
{
Alert.show("Do you want to Leave Table?","Confirmation",Alert.YES|Alert.NO,this,closeAlert1);
}
}
private function closeAlert1(event:CloseEvent):void{
if(event.detail==Alert.YES)
{
viewStack.removeChildAt(1);
}
}
private function closeAlert3(event:CloseEvent):void{
if(event.detail==Alert.YES)
{
viewStack.removeChildAt(2);
}
}
private function loadmodule():void
{
pb = new ProgressBar();
pb.labelPlacement = "center";
pb.label = "Loading %3 %";
progressContainer = new Box();
progressContainer.percentWidth = 100;
progressContainer.percentHeight = 100;
progressContainer.setStyle("horizontalAlign", "center");
progressContainer.setStyle("verticalAlign", "middle");
progressContainer.addChild(pb);
can.addChild(progressContainer);
var moduleUrl:String="../bin-debug/modules/useModule.swf";
info=ModuleManager.getModule(moduleUrl);
if(info!=null)
{
info.addEventListener(ModuleEvent.READY, modEventHandler);
info.addEventListener(ModuleEvent.ERROR,modErrorHandler);
info.load();
}
}
private function modEventHandler(e:ModuleEvent):void
{
info.removeEventListener(ModuleEvent.READY, modEventHandler);
info.removeEventListener(ModuleEvent.ERROR, modErrorHandler);
can.removeAllChildren();
if(module==null)
{
module = info.factory.create() as UIComponent;
if(module!=null)
{
module.x=0;
module.y=0;
module.percentWidth=100;
module.percentHeight=100;
can.addChild(module);
if(module is AModule)
{
}
}
}
}
private function modErrorHandler(event:ModuleEvent):void {
//cleanup and display an error alert
info.removeEventListener(ModuleEvent.READY, modEventHandler);
info.removeEventListener(ModuleEvent.ERROR, modErrorHandler);
info = null;
Alert.show(event.toString(), "Error Loading Module");
unloadModule();
}
private function unloadModule():void
{
can.removeAllChildren();
if (module != null && info != null) {
info.addEventListener(ModuleEvent.UNLOAD, unloadEventHandler);
info.unload();
}
}
private function unloadEventHandler(e:ModuleEvent):void
{
info.removeEventListener(ModuleEvent.UNLOAD, unloadEventHandler);
module = null;
info = null;
}
]]>
</mx:Script>
<mx:Canvas width="700" height="400" x="166" y="32">
<mx:ViewStack id="viewStack" width="100%" height="100%">
<mx:Canvas label="Button1" backgroundColor="#5EA5BA" visible="true" id="can1" >
<local:CustomButton label="Join" click="JoinClick(event)" x="536" y="222"/>
<mx:Label x="304" y="120" text="Label" id="username"/>
<mx:Label x="304" y="55" text="Label" id="status"/>
</mx:Canvas>
</mx:ViewStack>
</mx:Canvas>
<custom:CustomControlBar x="166" y="423" id="ctbb">
<custom:CustomToggleButtonBar dataProvider="viewStack"/>
</custom:CustomControlBar>
</mx:Application>
useModule.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="508" height="218" implements="modules.AModule" backgroundColor="#F00F0F" creationComplete="addlabel();">
<mx:Script>
<![CDATA[
import mx.core.Application;
public var logsin:loginhere = new loginhere();
public function addlabel():void
{
lb1.text=logsin.username.text;
txt3.text=logsin.username.text;
trace(txt3.text);
trace(lb1.text);
}
]]>
</mx:Script>
<mx:TextInput id="txt3" x="30.5" y="10" width="79"/>
<mx:Label id="lb1" x="31.5" y="40" width="78" text="Will it Change?"/>
</mx:Module>
AModule.as (Its an interface)
package modules
{
import flash.events.IEventDispatcher;
public interface AModule extends IEventDispatcher
{
function addlabel():void;
}
}
I haven't looked through the entire code, but one thing I noticed is that you should pass the values on as parameters to the child components and use data binding to dynamically update parameters.
So in AModule.as:
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="508" height="218" implements="modules.AModule" backgroundColor="#F00F0F" creationComplete="addlabel();">
<mx:Script>
<![CDATA[
import mx.core.Application;
public var logsin:loginhere = new loginhere();
[Bindable]
public var username:String = "";
]]>
</mx:Script>
<mx:TextInput id="txt3" text="{username}" x="30.5" y="10" width="79"/>
<mx:Label id="lb1" text="{username}" x="31.5" y="40" width="78" text="Will it Change?"/>
</mx:Module>
In the method where you create the module you can then:
module.username = //var that holds username;
The point I missed was, I dint create a instance for interface in main.mxml
The var should be created in modEventHandler function In that function the below lines should be added
ichild=module as AModule;
ichild.addlabel(tt.text);
so the module gets called and the value is displayed in the label field.
Please let me know, if its wrong way of working. Thank You

Dynamically selecting a static embedded image?

Here's my current situation:
I have images embedded on a class.
package system
{
public class Embedded
{
[Embed(source="assets/srcorangeboxidle.png")]
public static const btnSrcOrangeBoxIdle:Class;
[Embed(source="assets/srcorangeboxpressed.png")]
public static const btnSrcOrangeBoxPressed:Class;
[Embed(source="assets/hl1idle.png")]
public static const btnHL1Idle:Class;
[Embed(source="assets/hl1pressed.png")]
public static const btnHL1Pressed:Class;
public function Embedded(){}
}
}
Now on my main MXML file, I have the following.
<?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">
<fx:Script>
<![CDATA[
import system.Embedded;
protected function toggleButtonState(target:Object,pressed:Boolean=false):void
{
var baseImageName:String = target.id.toString();
if (!pressed) {
target.source = Embedded.[baseImageName+"Idle"];
} else {
target.source = Embedded.[baseImageName+"Pressed"];
}
}
]]>
</fx:Script>
<s:Image id="btnSrcOrangeBox" x="107" y="245" source="{Embedded.btnSrcOrangeBoxIdle}" mouseDown="toggleButtonState(btnSrcOrangeBox,true)" mouseUp="toggleButtonState(btnSrcOrangeBox,false)"/>
<s:Image id="btnHL1" x="107" y="355" source="{Embedded.btnHL1Idle}" mouseDown="toggleButtonState(btnHL1,true)" mouseUp="toggleButtonState(btnHL1,false)"/>
</s:Application>
As you can tell, the above codes don't seem to do the trick. I just want to dynamically select which Embedded.* class to select. Any help or hint will be greatly appreciated.
Remove the dot after the class name. The following should work:
target.source = Embedded[baseImageName + "Idle"];