1 Reply Latest reply on Dec 4, 2014 1:25 AM by BokJr

    initializer for 'states', type spark.components.Application is not assignable to target Array element type mx.states.State

    BokJr

      Here is my code, I'm trying to input a login/register screen to it but cannot get it to work, I am a complete newbie to Flex/Flash coding, so any help will be greatly appreciated (fixing the code so the login register screen works will be even more appreciated)

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

          xmlns:s="library://ns.adobe.com/flex/spark"

          xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" minWidth="240" minHeight="240"

          creationComplete="application1_creationCompleteHandler(event)">

        <fx:Style source="assets/styles.css"/>

        <fx:Declarations>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

        <!--<fx:XML id="questionsXml" source="data/questions.xml" />-->

        <s:RadioButtonGroup id="answersGroup"/>

        </fx:Declarations>

        <fx:Script>

        <![CDATA[

        import classes.Answer;

        import classes.Question;

       

        import mx.collections.ArrayCollection;

        import mx.controls.Alert;

        import mx.events.FlexEvent;

       

        import spark.components.RadioButton;

       

        private var currentQuestion:int = 0;

        private var questionsXml:XML;

        /* [Bindable]

        private var questions:ArrayCollection = new ArrayCollection([

        new Question("In a plus powered lens light rays do what?", new ArrayCollection([

        new Answer("Diverge", false),

        new Answer("Displays a rainbow", false),

        new Answer("Converge", true),

        new Answer("Do Nothing", false)

        ])),

        new Question("In a minus powered lens light rays do what?", new ArrayCollection([

        new Answer("Displays a rainbow", false),

        new Answer("Converge", false),

        new Answer("Do Nothing", false),

        new Answer("Diverge", true)

        ])),

        new Question("Light enters a lens &amp; converges at a point 50cm behind the lens, what is the power?", new ArrayCollection([

        new Answer("-0.25 Diopters", false),

        new Answer("+0.02 Diopters", false),

        new Answer("+2.00 Diopters", true),

        new Answer("-2.00 Diopters", false)

        ])),

        new Question("Using Prentice's Rule a -4.00 lens must be decentered by what to induce 1.00 Prism Diopter", new ArrayCollection([

        new Answer("1.0mm", false),

        new Answer("2.5mm", true),

        new Answer("10mm", false),

        new Answer("2.0cm", false)

        ])),

        new Question("When the direction of light changes as it passes from one medium to another, it is called?", new ArrayCollection([

        new Answer("Reflection", false),

        new Answer("Refraction", true),

        new Answer("Diffusion", false),

        new Answer("Retraction", false)

        ])),

        new Question("The focal length of a +2 diopter lens is?", new ArrayCollection([

        new Answer("2 cm", false),

        new Answer("5 cm", false),

        new Answer("50cm", true),

        new Answer("2 m", false)

        ])),

        new Question("One of the ways of identifying a lens with minus power is to look for?", new ArrayCollection([

        new Answer("Parallel rays of light coming to a point focus behind lens", false),

        new Answer("Lens thicker in the center than the edge", false),

        new Answer("Lens thicker in the edge than the centre", true),

        new Answer("Objects seen through the lens appear larger", false)

        ])),

        new Question("A lens clock is used to measure?", new ArrayCollection([

        new Answer("Astigmatism", false),

        new Answer("Pupillary Distance", false),

        new Answer("Vertex Distance", false),

        new Answer("Base Curve", true)

        ])),

        new Question("Transpose the following prescription +2.25/+1.75x85", new ArrayCollection([

        new Answer("+2.25/-1.75x85", false),

        new Answer("-4.00/+1.75x175", false),

        new Answer("+4.00/-1.75x175", true),

        new Answer("-2.25/-1.75x175", false)

        ])),

        new Question("the front power of a lens is +2.00 then the back surface power -8.25 what is the lens power?", new ArrayCollection([

        new Answer("-6.25", true),

        new Answer("-5.75", false),

        new Answer("+2.00", false),

        new Answer("-8.25", false)

        ])),

        new Question("Spectacle prescriptions are written in?", new ArrayCollection([

        new Answer("Axis", false),

        new Answer("Prisms", false),

        new Answer("Diopters", true),

        new Answer("Degrees", false)

        ])),

        new Question("Plus lenses ________ Minus lenses _________", new ArrayCollection([

        new Answer("Magnify, Minify", true),

        new Answer("Minify, Magnify", false),

        new Answer("Neutralize, Verify", false),

        new Answer("Myopia, Hyperopia", false)

        ])),

        new Question("A lens having one concave surface one convex surface is called what type of lens?", new ArrayCollection([

        new Answer("Bi-Convex", false),

        new Answer("Meniscus", true),

        new Answer("Bi-Concave", false),

        new Answer("Toric", false)

        ])),

        new Question("A myope has a prescription of the following kind of power?", new ArrayCollection([

        new Answer("Minus Power", true),

        new Answer("Plus Power", false),

        new Answer("Cylinder Power", false),

        new Answer("Sphero-Cylindrical", false)

        ])),

        new Question("A Hyperope has a prescription in the following kind of power?", new ArrayCollection([

        new Answer("Minus Power", false),

        new Answer("Plus Power", true),

        new Answer("Cylinder Power", false),

        new Answer("Sphero-Cylindrical", false)

        ])),

        new Question("What does PD stand for?", new ArrayCollection([

        new Answer("Pupillary Divergance", false),

        new Answer("Pupillary Display", false),

        new Answer("Pupillary Distance", true),

        new Answer("Pupillary Detail", false)

        ])),

        new Question("Where do you measure a progressive lens to?", new ArrayCollection([

        new Answer("Pupil center", true),

        new Answer("Pupil center minus 2mm", false),

        new Answer("Lower eyelid", false),

        new Answer("Distance between the pupils", false)

        ])),

        new Question("Where do you measure a Bifocal lens to?", new ArrayCollection([

        new Answer("Pupil center", false),

        new Answer("Pupil Centre less 4mm", false),

        new Answer("Lower eyelid less 2mm", true),

        new Answer("Lower eyelid less 1mm", false)

        ])),

        new Question("Where do you measure a Access lens to?", new ArrayCollection([

        new Answer("Pupil center", true),

        new Answer("Pupil Center less 3mm", true),

        new Answer("Pupil Center Less 1mm", false),

        new Answer("Pupil Center less 4mm", false)

        ])),

        new Question("When measuring a Bifocal for a child where do you measure to?", new ArrayCollection([

        new Answer("Pupil Centre less 3mm", false),

        new Answer("Lower Eyelid less 2mm", false),

        new Answer("Pupil Center", true),

        new Answer("As per Optometrists advice", false)

        ])),

        new Question("Where should an Aspheric High Index height be measured to", new ArrayCollection([

        new Answer("Centre of rotation rule - pupil centre minus 1mm for 2degrees panto tilt", true),

        new Answer("Centre Pupil less 4mm", false),

        new Answer("Centre Pupil", false),

        new Answer("Centre Pupil less 2mm", false)

        ])),

        new Question("On an optical cross for +2.25/-3.75x90 what powers are found on 180 meridian", new ArrayCollection([

        new Answer("-3.75", false),

        new Answer("-1.50", true),

        new Answer("+1.50", false),

        new Answer("+2.25", false)

        ]); */ 

        [Bindable]

        private var questions:ArrayCollection

       

        protected function application1_creationCompleteHandler(event:FlexEvent):void

        {

        //startTest();

        //readQuestionsXml();

        var ul:URLLoader = new URLLoader();

        ul.addEventListener(Event.COMPLETE, onQuestionsLoaded);

        ul.load(new URLRequest("data/questions.xml"));

        }

       

        private function onQuestionsLoaded(e:Event):void {

        questionsXml = new XML(e.target.data);

        readQuestionsXml();

        }

       

        private function readQuestionsXml():void

        {

        questions = new ArrayCollection();

        for each(var qXml:XML in questionsXml.question){

        var answers:ArrayCollection = new ArrayCollection();

        for each(var aXml:XML in qXml.answer){

        var a:Answer = new Answer(aXml.@text, aXml.@correct == "true");

        answers.addItem(a);

        }

        var q:Question = new Question(qXml.@questionText, answers);

        questions.addItem(q);

        }

        startTest();

        }

       

        private function startTest():void

        {

        currentState = "questions";

        currentQuestion = 0;

        if(questions.length == 0)

        return;

        ShowQuestion();

        }

       

        private function ShowQuestion():void

        {

        var q:Question = questions[currentQuestion] as Question;

        questionText.text = (currentQuestion+1) + ") " + q.questionText;

        answersVG.removeAllElements();

        for(var i:int=0; i< q.answers.length; i++)

        {

        var a:Answer = q.answers[i] as Answer;

        var rb:spark.components.RadioButton = new spark.components.RadioButton();

        rb.label = a.text;

        rb.value = a;

        rb.group = answersGroup;

        answersVG.addElement(rb);

        }

        }

       

        private function SubmitAnswer():void

        {

        (questions[currentQuestion] as Question).userSelectedAnswer = answersGroup.selectedValue as Answer;

        NextQuestion();

        }

       

        private function NextQuestion():void

        {

        if(++currentQuestion < questions.length)

        ShowQuestion();

        else

        ShowSummary();

        }

       

        private function ShowSummary():void

        {

        currentState = "results";

        }

        ]]>

        </fx:Script>

        <s:states>

        <!-- states\Login.mxml -->

        <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

          xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">

        <!-- The Application class states property defines the view states.-->

        <s:states>

        <s:State name="default" />

        <s:State name="Register" />

        </s:states>

        <!-- Set title of the Panel container based on the view state.-->

        <s:Panel id="loginPanel" title="Login" title.Register="Register">

        <s:layout>

        <s:VerticalLayout />

        </s:layout>

        <mx:Form id="loginForm">

        <mx:FormItem label="Username:">

        <s:TextInput />

        </mx:FormItem>

        <mx:FormItem label="Password:">

        <s:TextInput />

        </mx:FormItem>

        <mx:FormItem id="confirm" label="Confirm:" includeIn="Register">

        <!--

        Add a TextInput control to the form for the Register view state.

        -->

        <s:TextInput />

        </mx:FormItem>

        <mx:FormItem direction="horizontal">

        <!-- Use the LinkButton to change view state.-->

        <mx:Spacer width="100%" id="spacer1" />

        <!-- Set label of the control based on the view state.-->

        <mx:LinkButton id="registerLink" label="Need to Register?"

          label.Register="Return to Login" click="currentState='Register'"

          click.Register="currentState=''" />

        <s:Button id="loginButton" label="Login" label.Register="Register" />

        </mx:FormItem>

        </mx:Form>

        </s:Panel>

        </s:Application>

       

        <s:State name="questions"/>

        <s:State name="results"/>

        </s:states>

        <s:VGroup width="100%" height="100%" includeIn="questions,results">

        <s:Group width="100%">

        <s:Rect width="100%" height="100%">

        <s:fill>

        <s:SolidColor color="0xCCCCCC"/>

        </s:fill>

        </s:Rect>

        <s:Label left="100" top="30" bottom="30" fontWeight="bold" fontSize="20" text="Subject: Lenses"/>

        </s:Group>

        <s:Group width="100%" height="100%">

        <s:VGroup width="100%" height="100%" paddingTop="30" paddingBottom="30" paddingLeft="100" paddingRight="100" includeIn="questions">

        <s:Label id="questionText" styleName="QuestionText"/>

        <s:VGroup id="answersVG">

       

        </s:VGroup>

        <s:Spacer height="100%"/>

        </s:VGroup>

        <s:VGroup id="resultsSummary" width="100%" height="100%" paddingTop="30" paddingBottom="30" paddingLeft="100" paddingRight="100" includeIn="results">

        <s:List dataProvider="{questions}" itemRenderer="renderers.ResultQuestionRenderer"

        width="100%" height="100%" borderVisible="false"/>

        </s:VGroup>

        </s:Group>

        <s:Group width="100%">

        <s:Rect width="100%" height="100%">

        <s:fill>

        <s:SolidColor color="0xCCCCCC"/>

        </s:fill>

        </s:Rect>

        <s:Button right="100" bottom="30" top="30" label="Next" click="SubmitAnswer()" includeIn="questions"/>

        <s:Button right="100" bottom="30" top="30" label="Restart test" click="startTest()" includeIn="results"/>

        </s:Group>

        </s:VGroup>

      </s:Application>