开发者

Problem with displaying AS3 code in Flex

I have AS3 script bitfade.text.steel returning type Sprite. It works in Flash environment but not in FLEX. In Flex it displays nothing. No errors appear. It looks like the attached code also works. I use Flex SDK 4.5

Can you give me a clue what the problem with this code might be?

English is not my native language. If there are any errors please correct me.

Chris

<?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" minWidth="955" minHeight="600"                            
                creationComplete="creationComplete();" >                                                            
    <fx:Declarations>                                                                                               
        <!-- Place non-visual elements (e.g., services, value objects) here -->                                     
    </fx:Declarations>                                                                                              
    <fx:Script>                                                                                                     
        <![CDATA[                                                                                                   
            import bitfade.text.steel;                                                                              
            import flash.display.Sprite;                                                                            
            import mx.core.UIComponent;                                                                             

            function creationComplete(){                                                                            
                var textSteel = new steel("config.xml");                                                            
                if(textSteel is Sprite){                                                                            
                    trace("it is a sprite");                                                                        
                }                                                                                                   
                //var textSteelName:String = getQualifiedClassName(textSteel);                                      
                //trace(textSteelName);                                                                             
                textSteel.x = 150;                                                                                  
                trace("this is visible on the screen");                                                             
                var sprite:Sprite = new Sprite();                                                                   
                sprite.graphics.beginFill(0xFFCC00);                                                                
                sprite.graphics.drawCircle( 40, 40, 40 );                                                           
                sprite.graphics.endFill();                                                                          

                var wrapper:UIComponent = new UIComponent();                                                        
                wrapper.addChild(sprite);                                                                           
                wrapper.addChild(textSteel);                                                                        
                animationStage.addElement(wrapper);                                                                 
            }                                                                                    开发者_高级运维                   
        ]]>                                                                                                         
    </fx:Script>                                                                                                    
    <s:Group id="animationStage" visible="true" x="50" y="50">                                                      
        <s:Label text="test">                                                                                       

        </s:Label>                                                                                                  
    </s:Group>                                                                                                      
</s:WindowedApplication>                                                                                            


If I switch your custom class to a Sprite, and draw something on it, it shows up. Therefore I Believe there is a bug within your steel class. A sprite won't have any size until something is inside it with a size. There is no indication of the code you've shown what happens inside your steel class.

My sample:

<?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" creationComplete="creationComplete();">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>                                                                                                     
        <![CDATA[                                                                                                   
//          import bitfade.text.steel;                                                                              
            import flash.display.Sprite;

            import mx.core.UIComponent;                                                                             

            public function creationComplete():void{                                                                            
                var textSteel : Sprite = new Sprite();                                                            
                if(textSteel is Sprite){                                                                            
                    trace("it is a sprite");                                                                        
                }                                                                                                   

                //var textSteelName:String = getQualifiedClassName(textSteel);                                      
                //trace(textSteelName);                                                                             
                textSteel.x = 150;                                                                                  

                // JH Code added new
                textSteel.graphics.beginFill(0xFFCC00);                                                                
                textSteel.graphics.drawRect(0,0,100,100);                                                           
                textSteel.graphics.endFill();                                                                          

                trace("this is visible on the screen");                                                             
                var sprite:Sprite = new Sprite();                                                                   
                sprite.graphics.beginFill(0xFFCC00);                                                                
                sprite.graphics.drawCircle( 40, 40, 40 );                                                           
                sprite.graphics.endFill();                                                                          

                var wrapper:UIComponent = new UIComponent();                                                        
                wrapper.addChild(sprite);                                                                           
                wrapper.addChild(textSteel);                                                                        
                animationStage.addElement(wrapper);                                                                 
            }                                                                                                       
        ]]>                                                                                                         
    </fx:Script>                                                                                                    
    <s:Group id="animationStage" visible="true" x="50" y="50">                                                      
        <s:Label text="test">                                                                                       

        </s:Label>                                                                                                  
    </s:Group>      

</s:WindowedApplication>


I think you need to set the width and height of the wrapper UIComponent instance.

UIComponents don't automatically resize to their content so it's showing up with a width and height of 0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜