Проблема визуального элемента Flex 4 Sprite - PullRequest
0 голосов
/ 04 мая 2011

У меня есть следующий класс ActionScript 3.0:

public class ShopRaider extends Sprite {
public function ShopRaider () {
    // some code
}

}

У меня есть файл .mxml приложений как таковой:

<s:Application name="Spark_SpriteVisualElement_addChild_test"
           xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           initialize="init();">

<fx:Script>
    <![CDATA[
        import com.ShopRaider;
        private var game:ShopRaider;

        private function init():void
        {
            game = new ShopRaider();
            con.addChild(game);
        }
    ]]>
</fx:Script>

<s:SpriteVisualElement id="con" width="640" height="480" ></s:SpriteVisualElement>

когда я запускаю приложение, я получаю следующую ошибку:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at spark.components::Application/initialize()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Application.as:907]
at ShopRaider/initialize()
at spark.core::SpriteVisualElement/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2053]
at spark.core::SpriteVisualElement/addChild()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2010]
at ShopRaider/init()[C:\Users\ltadmin\Adobe Flash Builder 4\ShopRaider\src\ShopRaider.mxml:16]
at ShopRaider/___ShopRaider_Application1_initialize()[C:\Users\ltadmin\Adobe Flash Builder 4\ShopRaider\src\ShopRaider.mxml:6]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at mx.core::UIComponent/set processedDescriptors()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1630]
at mx.core::UIComponent/initializationComplete()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:7280]
at mx.core::UIComponent/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:7259]
at spark.components::Application/initialize()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Application.as:916]
at ShopRaider/initialize()
at spark.core::SpriteVisualElement/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2053]
at spark.core::SpriteVisualElement/addChild()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2010]
at ShopRaider/init()[C:\Users\ltadmin\Adobe Flash Builder 4\ShopRaider\src\ShopRaider.mxml:16]
at ShopRaider/___ShopRaider_Application1_initialize()[C:\Users\ltadmin\Adobe Flash Builder 4\ShopRaider\src\ShopRaider.mxml:6]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at mx.core::UIComponent/set processedDescriptors()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1630]
at mx.core::UIComponent/initializationComplete()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:7280]
at mx.core::UIComponent/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:7259]
at spark.components::Application/initialize()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Application.as:916]
at ShopRaider/initialize()
at mx.managers.systemClasses::ChildManager/childAdded()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\systemClasses\ChildManager.as:189]
at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\systemClasses\ChildManager.as:341]
at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2810]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2637]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2539]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\preloaders\Preloader.as:515]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

Где я иду не так? Кажется, это самый простой пример, но я застрял. Пожалуйста, помогите !!

PS: я использую FLEX 4, Flash Player 10 и Flash Builder 4

Заранее спасибо:)

Ответы [ 2 ]

0 голосов
/ 23 августа 2011

Возможно, вы не создали экземпляр своего объекта con. Возможно ли, что линия

<s:SpriteVisualElement id="con" width="640" height="480" ></s:SpriteVisualElement>

не заключено в ваши <s:Application> </s:Application> скобки?

0 голосов
/ 04 мая 2011

используйте creationComplete="init();" вместо initialize="init();"

...