簡體   English   中英

ActionScript 3 (Flex) 中的 ComboBox

[英]ComboBox in ActionScript 3 (Flex)

我必須在我的 actionscript 項目(FLARManager + Away3D)中使用菜單,並且我想使用 combobox。 我嘗試但我失敗了。

我的簡單代碼是

import spark.components.ComboBox;
import mx.collections.ArrayCollection;

public class MyComboBox extends ComboBox
{
    public function MyComboBox()
    {
        super();

        var dp_ac:ArrayCollection = new ArrayCollection([ 
            {label: "test 1"}, 
            {label: "test 2"}, 
            {label: "test 2"}
        ]);
        this.dataProvider = dp_ac;
        this.labelField = "label";

        this.x=200;
        this.y=-200;
        this.width=20;
        this.height=10;
    }
}

然后,在我的項目文件中,我編寫代碼:

import aplicacion.MyComboBox;

import artedra.*;

import com.transmote.flar.FLARManager;
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.marker.FLARMarkerEvent;
import com.transmote.flar.tracker.FLARToolkitManager;

import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;

import spark.components.ComboBox;
import spark.components.Group;

[SWF(width="800", height="600", frameRate="30", backgroundColor="#C0C0C0")]

/**
 * 
 * @author Iago Laz
 * 
 */ 
public class ARapp extends Sprite {
    private var flarManager:FLARManager;
    private var activeMarker:FLARMarker;
    private var artedraManager:IARTeDraManager = new ARTeDraManager(stage);

    private var targetDetected:Boolean = new Boolean(false);
    private var next:Number = ARTeDraManager.GRID;

    public function ARapp () {          
        addEventListener(Event.ADDED_TO_STAGE,onAdded);     
    }

    private function onAdded (evt:Event) :void {
        removeEventListener(Event.ADDED_TO_STAGE,onAdded);
        flarManager = new FLARManager("../resources/flarConfig.xml",new FLARToolkitManager(),stage);

        flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED,onMarkerAdded);
        flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED,onMarkerUpdated);
        flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED,onMarkerRemoved);

        flarManager.addEventListener(Event.INIT,onFlarManagerInited);
    }

    private function onFlarManagerInited (evt:Event) :void {
        flarManager.removeEventListener(Event.INIT,onFlarManagerInited);

        artedraManager.showModel();
        artedraManager.showViews();
        artedraManager.showGridDots(ARTeDraManager.GRID);

        var g:Group = new Group();
        var cb:MyComboBox = new MyComboBox();
        g.addElement(cb);

        stage.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
        stage.addEventListener(Event.ENTER_FRAME,onEnterFrame);
    }

    private function reportKeyDown(event:KeyboardEvent):void {
        if(event.keyCode==32) {
            if(next==ARTeDraManager.DOTS)
                next=ARTeDraManager.EMPTY;
            else
                next++;
            artedraManager.showGridDots(next);
        }
    } 

    private function onMarkerAdded (evt:FLARMarkerEvent) :void {
        trace("["+evt.marker.patternId+"] added");
        activeMarker = evt.marker;
        targetDetected = true;
    }

    private function onMarkerUpdated (evt:FLARMarkerEvent) :void {
        activeMarker = evt.marker;
        targetDetected = true;
    }

    private function onMarkerRemoved(evt:FLARMarkerEvent):void
    {
        trace("["+evt.marker.patternId+"] removed");
        activeMarker = null;
        targetDetected = false;
    }

    private function onEnterFrame(evt:Event):void {
        if(activeMarker) {
            artedraManager.rotateShapes(activeMarker.rotationZ);
        }
        artedraManager.showSphereMarkerDetected(targetDetected);
        artedraManager.renderScenes();
    }
}

但它沒有顯示任何東西。 我想我錯過了一些東西,但我不知道是什么。

任何人都可以幫助我嗎?

使用錯誤消息進行編輯:

TypeError: Error #1009: No se puede acceder a una propiedad o a un m賯do de una referencia a un objeto nulo.
at mx.styles::StyleManager$/getStyleManager()[E:\dev\4.x\frameworks\projects\framework\src\mx\styles\StyleManager.as:125]
at mx.styles::StyleProtoChain$/getStyleManager()[E:\dev\4.x\frameworks\projects\framework\src\mx\styles\StyleProtoChain.as:970]
at mx.styles::StyleProtoChain$/initProtoChain()[E:\dev\4.x\frameworks\projects\framework\src\mx\styles\StyleProtoChain.as:149]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::initProtoChain()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:10446]
at mx.core::UIComponent/regenerateStyleCache()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:10509]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7213]
at mx.core::UIComponent/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:6943]
at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Group.as:1825]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Group.as:1416]
at spark.components::Group/addElementAt()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Group.as:1183]
at spark.components::Group/addElement()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Group.as:1141]
at aplicacion::ARapp/onFlarManagerInited()[C:\Users\Iago\workspace\PFG_ARTeDra\src\aplicacion\ARapp.as:75]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.transmote.flar::FLARManager/onTrackerComplete()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\FLARManager.as:1098]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.transmote.flar.tracker::FLARToolkitManager/onTrackerComplete()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\tracker\FLARToolkitManager.as:384]
at com.transmote.flar.tracker::FLARToolkitManager/initTracker()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\tracker\FLARToolkitManager.as:332]
at com.transmote.flar::FLARManager/onTrackerInited()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\FLARManager.as:1080]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.transmote.flar.tracker::FLARToolkitManager/checkForInitComplete()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\tracker\FLARToolkitManager.as:374]
at com.transmote.flar.tracker::FLARToolkitManager/onPatternsLoaded()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\tracker\FLARToolkitManager.as:364]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.transmote.flar.pattern::FLARPatternLoader/checkForLoadCompletion()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\pattern\FLARPatternLoader.as:205]
at com.transmote.flar.pattern::FLARPatternLoader/onPatternLoaded()[C:\Users\Iago\workspace\PFG_ARTeDra\src\com\transmote\flar\pattern\FLARPatternLoader.as:197]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

根據代碼,我猜你不是通過設置高度和寬度屬性來調整 ComboBox 的大小,或者通過設置 x 和 y 屬性來給它一個 position 。

這兩件事最常在 updateDisplayList 方法中完成。 在 Spark 架構中,updateDisplayList() 通常在皮膚 class 中實現。

更多信息:

http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_2.html

http://help.adobe.com/en_US/flex/using/WS460ee381960520ad-2811830c121e9107ecb-7fff.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM