3

I am using SWFLoader to load a swf file. The code is below:

<?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" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <mx:SWFLoader source="alerttesting.swf"/>
</s:Application>

And the alerttesing.swf code is given blow:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
            width="100%" height="100%" fontFamily="Arial" fontSize="12"
            xmlns:ilog="http://www.ilog.com/2007/ilog/flex"       
            xmlns:local="c7.views.apps.calendar.*"
            backgroundColor="#FFFFFF">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert
        public function testingalerta():void{
            Alert.show("sa;lfks;aljfa;sljf");
        }
    ]]>
</mx:Script>
<mx:Canvas>
    <mx:VBox>
        <mx:Button click="testingalerta()"/>
        <mx:Button label="aslkdfjasj" click="{Alert.show('sdfslfjlsjf;asjfa;sj');}"/>   
    </mx:VBox>
</mx:Canvas>


</mx:Application>

Every time I click the button I get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at mx.managers::PopUpManagerImpl/http://www.adobe.com/2006/flex/mx/internal::createModalWindow()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\PopUpManagerImpl.as:686]
    at mx.managers::PopUpManagerImpl/addPopUp()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\PopUpManagerImpl.as:401]
    at mx.managers::PopUpManager$/addPopUp()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\PopUpManager.as:193]
    at mx.controls::Alert$/show()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Alert.as:618]
    at alerttesting/abcd()[C:\Users\zee\Adobe Flash Builder 4.5\calendar\src\alerttesting.mxml:12]
    at alerttesting/___alerttesting_Button1_click()[C:\Users\zee\Adobe Flash Builder 4.5\calendar\src\alerttesting.mxml:16]

Can you explain how can I fix this issue.

Regards Zeeshan

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
Zeeshan Rang
  • 19,375
  • 28
  • 72
  • 100
  • Do both buttons give the error? – JeffryHouser Jul 13 '11 at 00:16
  • 1
    +1 for providing complete runnable code. – JeffryHouser Jul 13 '11 at 00:17
  • Thanks Flextras, yes both button give the same error. – Zeeshan Rang Jul 13 '11 at 00:19
  • Are these both from the same Flex SDK? Is your mx:Application Flex 3 and Spark Application Flex 4? – Jason Sturges Jul 13 '11 at 00:19
  • Along with Jason's last comment here, I think your issue is with mixing the Flex SDKs, although it's claimed that this should work I don't think it's generally a good idea due to the possibility of classes from one SDK resolving classes from another SDK version. There's some good info linked in this stackoverflow post as well http://stackoverflow.com/questions/4056686/loading-flex-modules-compiled-with-flex-4-sdk-into-an-application-compiled-with-f – shaunhusain Jul 13 '11 at 06:02
  • I'm slightly curious as to why you need to load an application into another application. Modules doesn't work for you? – J_A_X Jul 13 '11 at 12:18
  • Modules... I have not read about modules yet. maybe I should. But I have another question, is it still possible using modules that I can run a Flex3 compiles module from a Flex4.5 application? – Zeeshan Rang Jul 13 '11 at 16:41

2 Answers2

5

Jason was close. Not only do you have to import the PopUpManager but you also have to use it.

<fx:Script>
    <![CDATA[
        import mx.managers.PopUpManager;
        private var manager:PopUpManager;
    ]]>
</fx:Script>

I found the answer here.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
Clay3981
  • 704
  • 1
  • 5
  • 6
  • 1
    Your code had an error, so I fixed it. With that said, I'm not positive if this is the answer. I think it has more to do with the application domain being off since it's an application within an application. Can you confirm that this code works with his sample? – J_A_X Jul 13 '11 at 12:17
  • I ran the code as I had it originally and it worked. Your edits were unnecessary to get it to work but does improve the style and readability. – Clay3981 Jul 13 '11 at 15:31
1

I think you just need to import the mx PopUpManager.

Try adding an import to your app:

    <fx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;
        ]]>
    </fx:Script>
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80