6 Replies Latest reply on Oct 24, 2009 1:27 PM by Flex harUI

    Program doesnt respont when i add canvas on enterFrame function

    Piitelk

      Hello all!

       

      I have been making a simple aplication and i have a problem i cannot find the solution (neither why it is happening)

      The thing i want to do is to dynamically add a canvas containing a button to the application and then i want the canvas to be moved from the left side of screen to the right.

      So i have made the following code

       

       

       

      And it works just fine.

      The next step is instead of using the Canvas i use a custom canvas ..

      here is the CustomCanvas.mxml component

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
           <mx:Button label="ccccButton" />
      </mx:Canvas>
      
      

       

      then i change the following code line

            var ccanvas:Canvas = new Canvas()  

                to

            var ccanvas:CustomCanvas = new CustomCanvas();

       

      the result is that there is no canvas displayed at the screen...the program doesn't do anything....

      the most weird thing is that if i do not have an onEnterFrame function and i just add my custom canvas to the init() method it is been displayed properly. Even if i have an onEnterFrame but without changing the customCanvas's x value it is been displayed properly. But the moment i write in the

      onEnterFunction the code  ccanvas.x +=1 the program doesnt display anything.... But if i do that with the original  Canvas object it is all ok,,,

      What is happening here? how i can i make a custom canvas object and then be able to move it in a onEnterFrame method?

       

      Thank you!!!!!!

       

      PS...what is the tags for putting code in?  i used the plain tag ..i hope it can be readable

        • 1. Re: Program doesnt respont when i add canvas on enterFrame function
          Piitelk Level 1

          oops.. there is not main code...

           

          here it is

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
               
               <mx:Script>
                    <![CDATA[
                         import mx.containers.Canvas;
                         import mx.controls.Button;
                                        
                         var ccanvas:Canvas = new Canvas();
                         var canvasButton:Button = new Button();
                                        
                         public function init():void{
                              canvasButton.label="canvas Button";
                              ccanvas.x=100;
                              ccanvas.y=200;
                              ccanvas.addChild(canvasButton);
                                             addChild(ccanvas);
                              
                              addEventListener(Event.ENTER_FRAME, onEnterFrame);
                              
                         }
                         
                         public function onEnterFrame(event:Event):void{
                              ccanvas.x+=1;
                         }
                         
                    ]]>
               </mx:Script>
               
               
          </mx:Application>
          
          
          • 2. Re: Program doesnt respont when i add canvas on enterFrame function
            Flex harUI Adobe Employee

            The app is probably in an invalidation loop.  Every time you move the ccanvas the app goes through another layout pass and until there are no more pending layout passes, the app will not display.

             

            Instead of using creationComplete, try using:  applicationComplete="callLater(init)"

             

            That will give the app a chance to show up then start moving the Canvas.

             

             

            Alex Harui

            Flex SDK Developer

            Adobe Systems Inc.

            Blog: http://blogs.adobe.com/aharui

            • 3. Re: Program doesnt respont when i add canvas on enterFrame function
              Piitelk Level 1

              Thanks for aswering

              I have tried what you suggested but unfortunatelly I have the same results. The application works fine when i have a Canvas object created but when i create a CustomCanvas it doesn't display anything. It is realy ocward because the CustomCanvas is nothimg more from a canvas with a button ....

               

              I beleive that if that was the case you suggested the program shouldn't work when i create a Canvas object either..

               

              I don't know what is wrong but i suspect that it has something to do on how flash treats extended classes ..

              • 4. Re: Program doesnt respont when i add canvas on enterFrame function
                Flex harUI Adobe Employee

                It could still be an invalidation loop.  Put a breakpoint on LayoutManager.doPhasedInstantation.  It should eventually stop being called.  If not, then there's an invalidation loop and the component may never finish validating and become visible.

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                • 5. Re: Program doesnt respont when i add canvas on enterFrame function
                  Piitelk Level 1

                  Unfortunately I dont know how to put a break point at that class which I have not write.

                   

                  I made a similar code example :

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
                       <mx:Script>
                            <![CDATA[
                                              
                                 import mx.controls.Button;
                                 import mx.containers.Canvas;
                                 
                       //          var testCanvas1:Canvas = new Canvas();
                                 var testCanvas1:CustomCanvas = new CustomCanvas()
                                 
                                 public function init():void{
                                      testCanvas1.addChild(new Button());
                                      addEventListener(Event.ENTER_FRAME,onEnterFrame);
                                      
                                      addChild(testCanvas1);
                                 }
                                 
                                 public function onEnterFrame(event:Event):void{
                                      testCanvas1.x += 1;
                                 }
                            ]]>
                       </mx:Script>
                  </mx:Application>
                  

                   

                   

                  As far as i have tried when instead of canvas i put the custom cunvas the program does not run. So the next step i did; is to remove the

                  <mx:Button id="ccccButton"/ > from the custom canvas file . And by suprise it works...

                  i tried adding again differnet kinds of mxml component to the the custom  canvas file  and after i added something it stopped work.

                  But if i have a custom canvas and i add whatever i want to it to the main application with the customCanvas.addChild() method it works fine,,,,

                   

                  is that observation of any help?

                  • 6. Re: Program doesnt respont when i add canvas on enterFrame function
                    Flex harUI Adobe Employee

                    The source is part of the SDK.  Find mx.managers.LayoutManager, open it in the editor and set a breakpoint. 

                     

                    Alex Harui

                    Flex SDK Developer

                    Adobe Systems Inc.

                    Blog: http://blogs.adobe.com/aharui