0

我正在尝试将使用 MXML 描述视图的 Flex 移动应用程序更改为使用 AS3 创建视图的应用程序。我变了:

之前:Assessments.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:MobileApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                 xmlns:s="library://ns.adobe.com/flex/spark"     firstView="view.LoginView">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:MobileApplication>`

之后:Assessments.as

package {
import spark.components.MobileApplication;
import view.LoginView;

[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
public class Assessments extends MobileApplication{

    public function Assessments(){
        super();
        super.firstView = view.LoginView;
    }
}
}

但是,现在我收到错误消息:

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at mx.preloaders::Preloader/initialize()[E:\dev\hero_private_beta\frameworks\projects\framework\src\mx\preloaders\Preloader.as:258]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\hero_private_beta\frameworks\projects\framework\src\mx\managers\SystemManager.as:1977]
at mx.managers::SystemManager/initHandler()[E:\dev\hero_private_beta\frameworks\projects\framework\src\mx\managers\SystemManager.as:2479]

我相信这可能与 .as 版本中未设置命名空间有关?有任何想法吗?


更新

package view
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import net.airpoint.northgate.ui.components.AirpointNumericTextField;
import qnx.events.QNXApplicationEvent;
import qnx.system.QNXApplication;
import spark.components.Button;
import spark.components.Form;
import spark.components.FormHeading;
import spark.components.FormItem;
import spark.components.Label;
import spark.components.TextInput;
import spark.components.View;

public class LoginView extends View
{
    private var form:Form;

    private var usernameLabel:Label;
    private var usernameField:AirpointNumericTextField;
    private var passwordLabel:Label;
    private var passwordField:TextInput;
    private var submit:Button;

//  public var menu:AirpointAppMenu;

    public function LoginView()
    {

//      menu = new AirpointAppMenu();
//      QNXApplication.qnxApplication.addEventListener(QNXApplicationEvent.SWIPE_DOWN, showAppMenu);
        initializeUI();
    }

    public function showAppMenu(event:QNXApplicationEvent):void{
//      menu.show();

    }

    public function initializeUI():void{

        form = new Form();
        this.submit = new Button();
        this.submit.label = "Login...";
        form.defaultButton = this.submit;

        // Heading
        var fh:FormHeading = new FormHeading();
        fh.label = "Login";
        form.addElement(fh);

        // Username
        this.usernameField = new AirpointNumericTextField();
        var f1:FormItem = new FormItem();
        f1.label = "Username";
        f1.addElement(this.usernameField);

        // Password
        this.passwordField = new TextInput();
        this.passwordField.displayAsPassword =true;
        var f2:FormItem = new FormItem();
        f2.label = "Password";
        f2.addElement(this.passwordField);

        form.addElement(f1);
        form.addElement(f2);
        form.addElement(this.submit);
        this.addElement(form);

    }
}
}

在此处输入图像描述


更新 3 AssessmentsApp.as

package  {
import mx.events.FlexEvent;
import mx.styles.CSSStyleDeclaration;

import spark.components.Group;
import spark.components.MobileApplication;

import views.AssessmentsAppHome;

[SWF(height="600", width="1024", frameRate="30", backgroundColor="#000")]
public class AssessmentsApp extends MobileApplication{

    public function AssessmentsApp(){
        super();
        this.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
    }

    private function onAppComplete(e:FlexEvent):void
    {
        this.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
        firstView = views.AssessmentsAppHome;
    }
}
}

评估AppHome.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="Home">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup>
    <s:TextInput text="awdwdawd"/>
</s:VGroup>
</s:View>

错误

Preloader.as(在 displayClass 上失败 = new...)

// Create a new instance of the display class and attach it to the stage
    if (showDisplay)
    {
        displayClass = new displayClassName(); 
        // Listen for when the displayClass no longer needs to be on the stage
        displayClass.addEventListener(Event.COMPLETE,                                     displayClassCompleteHandler);
4

2 回答 2

1

你应该扩展Sprite(不是MobileApplication)。请参阅以下链接

于 2011-04-13T12:13:49.693 回答
1

试试这个:

package {
import spark.components.MobileApplication;
import view.LoginView;

[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
public class Assessments extends MobileApplication{

    public function Assessments(){
        super();
        this.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
    }

private function onAppComplete(e:FlexEvent):void
{
this.removeEventListener(FlexEvent.APPLICATION_COMPLETE, onAppComplete);
firstView = LoginView;
}
}

可能是您的 ViewNavigator 在尝试在构造函数中访问它时尚未实例化。

于 2011-04-13T13:10:26.273 回答