A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Question with Error 1046 then Error 1009

  1. #1
    Member
    Join Date
    Apr 2008
    Posts
    65

    resolved [RESOLVED] Question with Error 1046 then Error 1009

    Hi all,
    I have code on the first frame of timeline and code in a class file and when publishing I get Error 1046: Type was not found or was not a compile-time constant: MouseEvent. This error gets thrown on the frames where I have buttons and their corresponding MouseEvent code, thus the MouseEvent error I suppose.

    Although I don't know how to fix it, I tried adding import flash.events.*; to the first frame's code, which resolved the Error 1046, but then caused Error 1009: Cannot access a property or method of a null object reference pointing to line 29 of the class file which states container.addChild(btn);. - the last item in the class file below.

    Each set of code works fine by itself, but when used together causes a problem. Can someone assist with what I need to change? I suppose there is some sort of conflict with the MouseEvents?


    Code on the first frame:
    Actionscript Code:
    stop();
    //tried adding import flash.events.*; but it caused Error 1046
    I_acknowledge_btn.visible = false;
    var xmlData:XML = new XML();
    var theURL_ur:URLRequest = new URLRequest("webaddress/file.xml");
    var loader_ul:URLLoader = new URLLoader(theURL_ur);
    loader_ul.addEventListener("complete", fileLoaded);

    function fileLoaded(e:Event):void
    {
       xmlData = XML(loader_ul.data);

       acktitle_txt.text = xmlData.acktitle;
       ack_txt.text = xmlData.ack;
       I_acknowledge_btn.visible = true;
    }


        Enter_btn.visible = false;
        checkmark.visible= false;

    I_acknowledge_btn.addEventListener(MouseEvent.CLICK, fl_ClickToShow);

    function fl_ClickToShow(event:MouseEvent):void
    {
        Enter_btn.visible = true;
        checkmark.visible= true;
    }


    Enter_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_17);

    function fl_ClickToGoToAndStopAtFrame_17(event:MouseEvent):void
    {
        gotoAndStop("Menu");
    }

    Class file:
    Actionscript Code:
    package com.fladev.menu
    {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
       
        public class MenuClass extends MovieClip {
           
            private var urlLoader:URLLoader;
            private var urlRequest:URLRequest;
            private const XML_PATH:String = "xml.xml";
            private var xml:XML;
           
            public function MenuClass() {
               
                urlLoader = new URLLoader();
                urlLoader.load(new URLRequest(XML_PATH));
                urlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
            }
           
            private function xmlLoaded(e:Event):void
            {
                xml = new XML(e.target.data);
               
                for (var i:int = 0; i < xml.item.length(); i++) {
                    var btn:Button = new Button(xml.item[i].@title, xml.item[i].@frame, xml.item[i].@target, xml.@colorOver, xml.@colorOut);
                    btn.y = Math.floor(i * btn.height);
                    container.addChild(btn);
                }
            }
           
        }
       
    }

    Button Class (but I don't think the problem is here..could be wrong)
    Actionscript Code:
    package com.fladev.menu
    {
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import caurina.transitions.Tweener;
        import caurina.transitions.properties.ColorShortcuts;
        import flash.net.navigateToURL;
        import flash.net.URLRequest;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
       
        public class Button extends MovieClip  
        {
            private var link:String;
            private var colorOver:String;
            private var colorOut:String;
            private var target:String;
           
            public function Button(title:String, link:String, target:String, colorOver:String, colorOut:String) {          
                ColorShortcuts.init();
               
                this.colorOver = colorOver;
                this.colorOut = colorOut;
                this.link = link;                  
               
                txt.text = title.toUpperCase();
                txt.autoSize = TextFieldAutoSize.LEFT;
               
                this.buttonMode = true;
                this.mouseChildren = false;        
               
                this.addEventListener(MouseEvent.ROLL_OVER, over);
                this.addEventListener(MouseEvent.ROLL_OUT, out);
                this.addEventListener(MouseEvent.CLICK, click);
               
                Tweener.addTween(this.bg, { _color:this.colorOut, time:0 } );
            }
           
            private function over(e:MouseEvent):void
            {      
                Tweener.addTween(e.target.bg, { _color:this.colorOver, time:0.5, transition:"easeOutSine" } );
            }
           
            private function out(e:MouseEvent):void
            {
                Tweener.addTween(e.currentTarget.bg, { _color:this.colorOut, time:0.5, transition:"easeOutSine" } );
            }  
           
            private function click(e:MouseEvent):void
            {
                MovieClip(root).gotoAndStop(this.link);
            }
        }
       
    }
    Last edited by scadbrad; 03-16-2012 at 03:47 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Importing MouseEvent was the correct fix for your first error. The import you did takes care of that.

    The second error is saying that container is null at the time that line executes. You did not post the code where you create an instance of MenuClass (which, btw, should just be Menu). container is not defined in MenuClass, so I would have expected an error to that effect. If, somehow, container is a valid variable, then you still need to be sure it's initialized to something non-null before you reference properties of it. Your constructor kicks off a loader which will trigger xmlLoaded when it completes. There is no guarantee that your MenuClass instance will be on the display at that time. So if container is a child instance, then it is entirely possible it has not been initialized yet.

  3. #3
    Member
    Join Date
    Apr 2008
    Posts
    65
    Thanks for the reply. container is a Movie Clip in my library that points to the class file com.fladev.menu.MenuClass.

    There is an instance of container on the stage where it should be pulling in an XML menu. The instance of container has an instance name of container.

    I hope that helps.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That makes little to no sense.

    I think you probably should remove the "container." part of "container.addChild(btn)" to make it just
    Code:
    addChild(btn);
    If your container library symbol is linked to MenuClass, then your container instance IS a MenuClass. If you want your buttons to be added to your container instance, then just add them to it with addChild which is equivalent to this.addChild.

    I have no idea why it compiled at all, since the identifier "container" is undefined in MenuClass.

  5. #5
    Member
    Join Date
    Apr 2008
    Posts
    65
    Resolved.
    container.addChild(btn); needed to be changed to this.addChild(btn); AND my project was incorrectly set to the MenuClass when instead I should have had my Container Movie Clip set to MenuClass in Linkage.

    thanks!

  6. #6
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    I assume that you are in danger.

    If this is going on, you might never noticed what you did at the entry of that frame every time after visiting the link page.

    I am sure you are not aware of your coming danger in your future programming concept.

    To test what I am saying put two trace and test your project again.

    One is here:

    Actionscript Code:
    private var xml:XML;
    private static var count:int=0;
           
    public function MenuClass() {
      trace(MenuClass.count++);
    //......

    }

    And other is here:

    Actionscript Code:
    private function xmlLoaded(e:Event):void {
      trace(e.target);
    //.....
    }

    Come back and ask for solution if needed.

    The Button Class looks horrible to me, including the name of that class.



    marlopax
    Last edited by marlopax; 03-17-2012 at 05:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center