thanks a lot, it worked. I still dont understand why is that difference. Why was that not working when called from parent button.
On Fri, Feb 11, 2011 at 4:44 PM, skmani <[email protected]> wrote: > hi > i don't know weather its help full for you . > > place the button inside the module and get the URL from the parent > application and set inside the module as shown below > > > headerMod.mxml > -------------------------- > > <?xml version="1.0" encoding="utf-8"?> > <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute"> > <mx:Script> > <![CDATA[ > [Embed(source="assets/images/jpl_head.png")] > [Bindable] > public var headerImgCls:Class; > > public function changeUserPic(picUrl:String):void{ > userPics.source = picUrl; > } > private function asssignData():void > { > userPics.source=parentApplication.getURL(); > } > ]]> > </mx:Script> > <mx:Canvas> > <mx:Image id="hdImg" width="1000" height="75" > source="{headerImgCls}"/> > <mx:Image id="userPics" x="924" y="9" > width="54" height="54"/> > <mx:Button x="143" y="154" label="Button" click="asssignData()"/> > </mx:Canvas> > </mx:Module> > > > > index.mxml > ----------------- > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > backgroundColor="#f2f2f2" backgroundAlpha="1" > layout="absolute" width="1000" height="800" > xmlns:view="com.jpl.view.*" creationComplete="init()"> > <mx:Script> > <![CDATA[ > import mx.controls.Alert; > import com.jpl.modules.*; > import mx.events.ModuleEvent; > import mx.modules.ModuleManager; > import mx.modules.IModuleInfo; > > private var moduleInfo:IModuleInfo; > private function init():void{ > loadHeader(); > } > > private var jpl_head:Object; > //loading header into application > private function loadHeader():void{ > mod_progress.visible = true; > moduleInfo = ModuleManager.getModule( > "com/jpl/modules/ > headerMod.swf" ); > moduleInfo.addEventListener( > ModuleEvent.READY, > onHeaderModuleReady); > > moduleInfo.addEventListener(ModuleEvent.ERROR, > handleHeaderModuleError); > > moduleInfo.addEventListener(ModuleEvent.PROGRESS, > onHeaderModuleProgress); > moduleInfo.load(); > } > protected function > onHeaderModuleReady( moduleEvent:ModuleEvent ):void{ > jpl_head = moduleInfo.factory.create() as > headerMod; > > mod_holder.addChild(moduleInfo.factory.create() as DisplayObject); > trace('Module successfully loaded : '+ > moduleEvent.module.url); > mod_progress.label = "" > mod_progress.visible = false; > } > protected function > handleHeaderModuleError( moduleEvent:ModuleEvent ):void{ > throw new Error( "Module error loading : " + > moduleEvent.module.url ); > } > protected function > onHeaderModuleProgress( moduleEvent:ModuleEvent ):void{ > trace( "Downloading Module : "+ > moduleEvent.module.url ); > mod_progress.label = 'Loading Header'; > mod_progress.setProgress( > moduleEvent.bytesLoaded, > moduleEvent.bytesTotal ); > } > public function getURL():String > { > return 'video_icon.png'; > } > > ]]> > </mx:Script> > > <mx:Canvas id="mod_holder"> > </mx:Canvas> > > <mx:ProgressBar id="mod_progress" > width="300" indeterminate="true" > trackHeight="5" labelPlacement="top" > label="Loading .."/> > > </mx:Application> > > > > is this help full for u? > > > > > On Feb 10, 4:44 pm, Flex Hatter <[email protected]> wrote: > > I'm attaching the flex project archive of the above project. > > I'm still stuck in the same place. Can anybody help me... > > Flex 3.5 file > > > > > > > > > > > > > > > > On Fri, Feb 4, 2011 at 6:05 PM, Flex Hatter <[email protected]> > wrote: > > > Thanks for that. > > > I have tried debugging also.... What I have understood looking into > that > > > is, > > > inside the module the image components 'userPics' is not a image > component > > > instead it is a object with null assigned to it. I think thats the > reason > > > it is saying > > > 'Cannot access a property or method of a null object reference' > > > > > I have tried checking examples in the internet I found many examples > where > > > they will > > > be accessing function and variables inside the module and that is > working > > > for me too. > > > Have ever tried accessing UI component in module from main application. > > > > > On Fri, Feb 4, 2011 at 12:51 PM, Kronos <[email protected]> wrote: > > > > >> Sorry cant help u much... the code looks fine. However my guess is > > >> that your module is not getting loaded for some reason. > > >> Why dont u debug the code and see if ur onHeaderModuleReady function > > >> is getting called or not. The most likely expanation is that it isnt > > >> and because of that ur variable jpl_head never gets initialized. > > >> Another thing that u can see before debugging is when the application > > >> loads is the default image (jpl_head.png) getting displayed on the > > >> screen. If it is then there is something else wrong in the code and u > > >> wont find out without debugging. > > > > >> Sorry if I am stating the obvious. > > > > >> On Feb 3, 8:57 pm, Flex Hatter <[email protected]> wrote: > > >> > Hi all, > > > > >> > Im still stuck with this... anybody know solution for this? > > > > >> > On Thu, Jan 27, 2011 at 5:26 PM, Flex Hatter <[email protected] > > > > >> wrote: > > >> > > Hi all, > > > > >> > > I'm trying to use module in flex. I tried create a header module > which > > >> is > > >> > > loaded by the main > > >> > > application and should update the image component in the header. I > > >> have > > >> > > posted my code > > >> > > below. I cannot update the image component in header, please help > me > > >> in > > >> > > fixing the code and > > >> > > suggest me if any better way. > > > > >> > > *index.mxml* > > >> > > <?xml version="1.0" encoding="utf-8"?> > > >> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > >> > > backgroundColor="#f2f2f2" backgroundAlpha="1" > > >> > > layout="absolute" width="1000" height="800" > > >> > > creationComplete="init()"> > > >> > > <mx:Script> > > >> > > <![CDATA[ > > >> > > import mx.controls.Alert; > > >> > > import com.jpl.modules.*; > > >> > > import mx.events.ModuleEvent; > > >> > > import mx.modules.ModuleManager; > > >> > > import mx.modules.IModuleInfo; > > > > >> > > private var moduleInfo:IModuleInfo; > > >> > > private function init():void{ > > >> > > loadHeader(); > > >> > > } > > > > >> > > private var jpl_head:Object; > > >> > > //loading header into application > > >> > > private function loadHeader():void{ > > >> > > mod_progress.visible = true; > > >> > > moduleInfo = ModuleManager.getModule( > > >> > > "com/jpl/modules/headerMod.swf" ); > > >> > > moduleInfo.addEventListener( ModuleEvent.READY, > > >> > > onHeaderModuleReady); > > >> > > moduleInfo.addEventListener(ModuleEvent.ERROR, > > >> > > handleHeaderModuleError); > > >> > > > moduleInfo.addEventListener(ModuleEvent.PROGRESS, > > >> > > onHeaderModuleProgress); > > >> > > moduleInfo.load(); > > >> > > } > > >> > > protected function onHeaderModuleReady( > > >> > > moduleEvent:ModuleEvent ):void{ > > >> > > jpl_head = moduleInfo.factory.create() as > > >> headerMod; > > >> > > mod_holder.addChild(moduleInfo.factory.create() as > > >> > > DisplayObject); > > >> > > mod_progress.label = "" > > >> > > mod_progress.visible = false; > > >> > > } > > >> > > protected function handleHeaderModuleError( > > >> > > moduleEvent:ModuleEvent ):void{ > > >> > > throw new Error( "Module error loading : " + > > >> > > moduleEvent.module.url ); > > >> > > } > > >> > > protected function onHeaderModuleProgress( > > >> > > moduleEvent:ModuleEvent ):void{ > > >> > > mod_progress.label = 'Loading Header'; > > >> > > mod_progress.setProgress( moduleEvent.bytesLoaded, > > >> > > moduleEvent.bytesTotal ); > > >> > > } > > >> > > ]]> > > >> > > </mx:Script> > > > > >> > > <mx:Canvas id="mod_holder"> > > >> > > </mx:Canvas> > > > > >> > > <mx:ProgressBar id="mod_progress" > > >> > > width="300" indeterminate="true" > > >> > > trackHeight="5" labelPlacement="top" > > >> > > label="Loading .."/> > > >> > > <mx:Button x="143" y="154" label="Button" > > >> > > click="jpl_head.changeUserPic('video_icon.png');"/> > > > > >> > > </mx:Application> > > > > >> > > *headerMod.mxml* > > >> > > <?xml version="1.0" encoding="utf-8"?> > > >> > > <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" > > >> layout="absolute"> > > >> > > <mx:Script> > > >> > > <![CDATA[ > > >> > > [Embed(source="assets/images/jpl_head.png")] > > >> > > [Bindable] > > >> > > public var headerImgCls:Class; > > > > >> > > public function changeUserPic(picUrl:String):void{ > > >> > > userPics.source = picUrl; > > >> > > } > > >> > > ]]> > > >> > > </mx:Script> > > >> > > <mx:Canvas> > > >> > > <mx:Image id="hdImg" width="1000" height="75" > > >> > > source="{headerImgCls}"/> > > >> > > <mx:Image id="userPics" x="924" y="9" > > >> > > width="54" height="54"/> > > >> > > </mx:Canvas> > > >> > > </mx:Module> > > > > >> > > *Error on clicking button in index.mxml* > > >> > > TypeError: Error #1009: Cannot access a property or method of a > null > > >> object > > >> > > reference. > > >> > > at > > > > >> > com.jpl.modules::headerMod/changeUserPic()[E:\FlexTraining\jlp\src\com\jpl\ > modules\headerMod.mxml:10] > > >> > > at > > >> > > > index/___index_Button1_click()[E:\FlexTraining\jlp\src\index.mxml:56] > > > > >> -- > > >> You received this message because you are subscribed to the Google > Groups > > >> "Flex India Community" group. > > >> To post to this group, send email to [email protected]. > > >> To unsubscribe from this group, send email to > > >> [email protected]. > > >> For more options, visit this group at > > >>http://groups.google.com/group/flex_india?hl=en. > > > > > > > > jlp2.zip > > 200KViewDownload > > -- > You received this message because you are subscribed to the Google Groups > "Flex India Community" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/flex_india?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Flex India Community" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.

