Re: [flexcoders] Moving a viewStack through actionscript

2009-03-10 Thread Wally Kolcz
I normally do dispatch custom events from my TitleWindows back to the parent, 
but was having a hard time figuring out how to pass the value of the selection 
(radiobutton) back to the parent to score.


From: Michael Wills mich...@mawills.com
Sent: Monday, March 09, 2009 3:21 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 

Hi Wally,
sorry I missed the hierarchy there. You have checkSingle on the module
and not the Viewstack. In that case, you should be able to do
parent.parent.checkSingle and leave out the cast as test1. So

public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a
test1 which of course isn't a viewstack. But I'm not sure about this
one because the parent.parent is a module. You could also forgo using
the testMod variable and in your click declaration instead of

click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue) /

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex
apps in the future, even though this one is not going to be a full-on
huge app, I'd learn about dispatching custom events. It's not that
complicated but it takes some time to understand. It would save some of
the hassle you're trying to do of course at the expense of a new and
different kind of hassle. :-)

Michael

Wally Kolcz wrote:

Wow...its a 'simple' one time create
app. 

All I want to do is when the user selects an answer on the
question1.mxml component, they can click a button,  pass the value of
the radio button to the test1 module's checkSingle() method  and
then move to the next question in the test1 module's stack. 

When I changed the function call on the button of question1.mxml to
test1(parent).checkSingle(group1.selectedValue);  mx:Button label=Next 
click=test1(parent).checkSingle(group1.selectedValue)
/ 

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert
mx.containers::viewst...@6563ae1 to com.ipexpert.tests.test1.

at 
com.ipexpert.questions.q1::question1/___question1_Button1_click()[D:\wkolcz\My
Documents\Flex Builder 
3\IPExpertBrainBuster\src\com\ipexpert\questions\q1\question1.mxml:21]

Here is checkSingle() and nextQuestionPlease()

public function checkSingle(answer:Object):void {

if (answer !=0) {

Application.application.score += 1;

}

currentQuestion += 1;

nextQuestionPlease();

}

public function nextQuestionPlease():void {

 questionsVS.selectedIndex=currentQuestion;

}


From: Michael Wills
mich...@mawills.com
Sent: Monday, March 09, 2009 11:44 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through
actionscript 

If I am understanding your code correctly, you actually want to
call 

test1(parent).checkSingle instead of testMod. The reason is
because you 

are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of
tightly 

coupled design. By that I mean, your question1 component knows about 

your test1 component. If it's a more complex app though, you may want
to 

look at decoupling your app. Otherwise this app will quickly become 

inflexible and harder to maintain as it grows.

In this case, you could set up your question components to dispatch an 

event that your test1 then listens to. That way question1 doesn't have 

to be directly connected to parent.

I hope that makes sense!

Michael

Wally Kolcz wrote:



 When I added the click=nextQuestion() it was triggered off
the 

 selecting of a radio button and not the button. Here all the code
I 

 have. It is telling me that the viewStack doesn't exist when I
believe 

 it should.



 test1.mxml



 ?xml version=1.0 encoding=utf-8?

 mx:Module xmlns:mx=http://www.adobe.com/2006/mxml;
layout=vertical 

 width=100% height=98% 

 xmlns:questions=com.ipexpert.questions.q1.* 

 creationComplete=initApp() 

 mx:Script

 ![CDATA[

 import mx.core.Application; 

 

 public var testID:int = 1;

 public var currentQuestion:int = 0;

 

 public function initApp():void {

 

 } 



 public function checkSingle(answer:Object):void {

 if (answer !=0) {

 Application.application.score += 1;

 }

 currentQuestion += 1;

 nextQuestionPlease();

 }

 

 public function nextQuestionPlease():void {

 }

 ]]

 /mx:Script

 mx:ViewStack id=questionsVS width=98% height=100% 

 paddingLeft=10

 

 questions:question1 /

 questions:question2 /

 questions:question3 /

 questions:question4 /

 /mx:ViewStack

 /mx:Module





 question1.mxml



 ?xml version=1.0

Re: [flexcoders] Moving a viewStack through actionscript

2009-03-10 Thread Wally Kolcz

Sorry to be a pain, but when I added the 
parent.parent.checkSingle() it gives me an error. 
1061: Call to a possibly undefined method checkSingle through a reference with 
static type flash.display:DisplayObjectContainer.

I though my problem was the 'public var testMod:test1 = new test1();', thinking 
the 'new test1()' was the problem. So I removed it and just set it to a local 
variable.  
public var testMod:test1; I was able to see the checkSingle 
method in the auto hinting. But when I try to run it now, I get that the 
testMod is null.

If I were to do the dispatchEvent route, I would have to attach it to the test1 
module, right? this.addEventListener(answered, checkSingle);.  How could I 
get the variable passed from the components (questions) to the module's 
checkSingle() method? There will be between 20-100 of these questions. 



From: Michael Wills mich...@mawills.com
Sent: Monday, March 09, 2009 3:21 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 


Hi Wally,
sorry I missed the hierarchy there. You have checkSingle on the module
and not the Viewstack. In that case, you should be able to do
parent.parent.checkSingle and leave out the cast as test1. So

public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a
test1 which of course isn't a viewstack. But I'm not sure about this
one because the parent.parent is a module. You could also forgo using
the testMod variable and in your click declaration instead of

click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue) /

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex
apps in the future, even though this one is not going to be a full-on
huge app, I'd learn about dispatching custom events. It's not that
complicated but it takes some time to understand. It would save some of
the hassle you're trying to do of course at the expense of a new and
different kind of hassle. :-)

Michael

Wally Kolcz wrote:


Wow...its a 'simple' one time create
app. 

All I want to do is when the user selects an answer on the
question1.mxml component, they can click a button,  pass the value of
the radio button to the test1 module's checkSingle() method  and
then move to the next question in the test1 module's stack. 

When I changed the function call on the button of question1.mxml to
test1(parent).checkSingle(group1.selectedValue);  

mx:Button label=Next 
click=test1(parent).checkSingle(group1.selectedValue)
/ 

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert
mx.containers::viewst...@6563ae1 to com.ipexpert.tests.test1.

at 
com.ipexpert.questions.q1::question1/___question1_Button1_click()[D:\wkolcz\My
Documents\Flex Builder 
3\IPExpertBrainBuster\src\com\ipexpert\questions\q1\question1.mxml:21]

Here is checkSingle() and nextQuestionPlease()

public function checkSingle(answer:Object):void {

if (answer !=0) {

Application.application.score += 1;

}

currentQuestion += 1;

nextQuestionPlease();

}

public function nextQuestionPlease():void {

 questionsVS.selectedIndex=currentQuestion;

}




From: Michael Wills
mich...@mawills.com
Sent: Monday, March 09, 2009 11:44 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through
actionscript 

If I am understanding your code correctly, you actually want to
call 

test1(parent).checkSingle instead of testMod. The reason is
because you 

are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of
tightly 

coupled design. By that I mean, your question1 component knows about 

your test1 component. If it's a more complex app though, you may want
to 

look at decoupling your app. Otherwise this app will quickly become 

inflexible and harder to maintain as it grows.

In this case, you could set up your question components to dispatch an 

event that your test1 then listens to. That way question1 doesn't have 

to be directly

RE: [flexcoders] Moving a viewStack through actionscript

2009-03-10 Thread Tracy Spratt
Put the change handler on the RadioButton group, and in that handler
dispatch your specially named, bubbling event.  In the handler for that
event, you can access the dispatching component through the reference in the
target or currentTarget property.  So you can access the value of the
RadioButtonGroup through that reference.

 

Tracy Spratt,

Lariat Services, development services available

  _  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Wally Kolcz
Sent: Tuesday, March 10, 2009 8:34 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript

 

Sorry to be a pain, but when I added the parent.parent.checkSingle() it
gives me an error. 
1061: Call to a possibly undefined method checkSingle through a reference
with static type flash.display:DisplayObjectContainer.

I though my problem was the 'public var testMod:test1 = new test1();',
thinking the 'new test1()' was the problem. So I removed it and just set it
to a local variable. public var testMod:test1; I was able to see the
checkSingle method in the auto hinting. But when I try to run it now, I get
that the testMod is null.

If I were to do the dispatchEvent route, I would have to attach it to the
test1 module, right? this.addEventListener(answered, checkSingle);.  How
could I get the variable passed from the components (questions) to the
module's checkSingle() method? There will be between 20-100 of these
questions. 



  _  

From: Michael Wills mich...@mawills.com
Sent: Monday, March 09, 2009 3:21 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 

Hi Wally, sorry I missed the hierarchy there. You have checkSingle on the
module and not the Viewstack. In that case, you should be able to do
parent.parent.checkSingle and leave out the cast as test1. So

public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a
test1 which of course isn't a viewstack. But I'm not sure about this one
because the parent.parent is a module. You could also forgo using the
testMod variable and in your click declaration instead of

click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue) /

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex apps
in the future, even though this one is not going to be a full-on huge app,
I'd learn about dispatching custom events. It's not that complicated but it
takes some time to understand. It would save some of the hassle you're
trying to do of course at the expense of a new and different kind of hassle.
:-)

Michael


Wally Kolcz wrote: 

Wow...its a 'simple' one time create app. 

All I want to do is when the user selects an answer on the question1.mxml
component, they can click a button,  pass the value of the radio button to
the test1 module's checkSingle() method  and then move to the next question
in the test1 module's stack. 

When I changed the function call on the button of question1.mxml to
test1(parent).checkSingle(group1.selectedValue); mx:Button label=Next
click=test1(parent).checkSingle(group1.selectedValue) / 

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert
mx.containers::viewst...@6563ae1 to com.ipexpert.tests.test1.
at
com.ipexpert.questions.q1::question1/___question1_Button1_click()[D:\wkolcz\
My Documents\Flex Builder
3\IPExpertBrainBuster\src\com\ipexpert\questions\q1\question1.mxml:21]

Here is checkSingle() and nextQuestionPlease()

public function checkSingle(answer:Object):void {
if (answer !=0) {
Application.application.score += 1;
}
currentQuestion += 1;
nextQuestionPlease();
}

public function nextQuestionPlease():void {

 questionsVS.selectedIndex=currentQuestion;
}





  _  


From: Michael Wills mich...@mawills.com
Sent: Monday, March 09, 2009 11:44 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 

If I am understanding your code correctly, you actually want to call 
test1(parent).checkSingle instead of testMod. The reason is because you 
are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of tightly 
coupled design. By that I mean, your question1 component knows about 
your test1 component. If it's a more complex app though, you may want to 
look at decoupling your app. Otherwise this app will quickly become 
inflexible and harder to maintain as it grows.

In this case, you could set up your question components to dispatch an 
event that your test1 then listens

RE: [flexcoders] Moving a viewStack through actionscript

2009-03-10 Thread Wally Kolcz
Would I put the dispatch on the radio button group of the 'Next' button?


From: Tracy Spratt tspr...@lariatinc.com
Sent: Tuesday, March 10, 2009 6:42 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Moving a viewStack through actionscript 

Put the change handler on the RadioButton
group, and in that handler dispatch your specially named, bubbling event.  In
the handler for that event, you can access the dispatching component through
the reference in the target or currentTarget property.  So you can access the
value of the RadioButtonGroup through that reference.   Tracy Spratt,  Lariat 
Services, development services
available 

 From: 
flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of 
Wally Kolcz
Sent: Tuesday, March 10, 2009 8:34
AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a
viewStack through actionscript   

Sorry to be a pain, but when I added the
parent.parent.checkSingle() it gives me an error. 

1061: Call to a possibly undefined method checkSingle through a reference with
static type flash.display:DisplayObjectContainer.

I though my problem was the 'public var testMod:test1 = new test1();', thinking
the 'new test1()' was the problem. So I removed it and just set it to a local
variable. public var testMod:test1; I was able to see the checkSingle method in
the auto hinting. But when I try to run it now, I get that the testMod is null.

If I were to do the dispatchEvent route, I would have to attach it to the test1
module, right? this.addEventListener(answered,
checkSingle);.  How could I get the variable passed from the
components (questions) to the module's checkSingle() method? There will be
between 20-100 of these questions. 


 From : Michael
Wills mich...@mawills.com
Sent: Monday, March 09, 2009 3:21
PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a
viewStack through actionscript 

Hi
Wally, sorry I missed the hierarchy there. You have checkSingle on the module
and not the Viewstack. In that case, you should be able to do 
parent.parent.checkSingle
and leave out the cast as test1. So

public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a test1
which of course isn't a viewstack. But I'm not sure about this one because the
parent.parent is a module. You could also forgo using the testMod variable and
in your click declaration instead of

click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue)
/

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex apps in
the future, even though this one is not going to be a full-on huge app, I'd
learn about dispatching custom events. It's not that complicated but it takes
some time to understand. It would save some of the hassle you're trying to do
of course at the expense of a new and different kind of hassle. :-)

Michael

Wally Kolcz wrote: 

Wow...its
a 'simple' one time create app. 

All I want to do is when the user selects an answer on the question1.mxml
component, they can click a button,  pass the value of the radio button to
the test1 module's checkSingle() method  and then move to the next
question in the test1 module's stack. 

When I changed the function call on the button of question1.mxml to
test1(parent).checkSingle(group1.selectedValue); mx:Button
label=Next click=test1(parent).checkSingle(group1.selectedValue)
/ 

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert 
mx.containers::viewst...@6563ae1
to com.ipexpert.tests.test1.

at 
com.ipexpert.questions.q1::question1/___question1_Button1_click()[D:\wkolcz\My
Documents\Flex Builder 
3\IPExpertBrainBuster\src\com\ipexpert\questions\q1\question1.mxml:21]

Here is checkSingle() and nextQuestionPlease()

public function checkSingle(answer:Object):void {

if
(answer !=0) {

Application.application.score += 1;

}

currentQuestion += 1;

nextQuestionPlease();

}

public function nextQuestionPlease():void {

 questionsVS.selectedIndex=currentQuestion;

}


 From : Michael
Wills mich...@mawills.com
Sent: Monday, March 09, 2009 11:44
AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a
viewStack through actionscript 

If I am
understanding your code correctly, you actually want to call 

test1(parent).checkSingle instead of testMod. The reason is because you 

are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of tightly 

coupled design. By that I mean, your question1

RE: [flexcoders] Moving a viewStack through actionscript

2009-03-10 Thread Wally Kolcz

Thank you tracy. That helps a lot. I got it to work!



From: Tracy Spratt tspr...@lariatinc.com
Sent: Tuesday, March 10, 2009 6:42 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Moving a viewStack through actionscript 


Put the change handler on the RadioButton
group, and in that handler dispatch your specially named, bubbling event.  In
the handler for that event, you can access the dispatching component through
the reference in the target or currentTarget property.  So you can access the
value of the RadioButtonGroup through that reference.


Tracy Spratt,


Lariat Services, development 
services
available




From:

flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of 
Wally Kolcz
Sent: Tuesday, March 10, 2009 8:34
AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a
viewStack through actionscript



Sorry to be a pain, but when I added the
parent.parent.checkSingle() it gives me an error. 

1061: Call to a possibly undefined method checkSingle through a reference with
static type flash.display:DisplayObjectContainer.

I though my problem was the 'public var testMod:test1 = new test1();', thinking
the 'new test1()' was the problem. So I removed it and just set it to a local
variable. public var testMod:test1; I was able to see the checkSingle method in
the auto hinting. But when I try to run it now, I get that the testMod is null.

If I were to do the dispatchEvent route, I would have to attach it to the test1
module, right? this.addEventListener(answered,
checkSingle);.  How could I get the variable passed from the
components (questions) to the module's checkSingle() method? There will be
between 20-100 of these questions. 





From



: Michael
Wills mich...@mawills.com
Sent: Monday, March 09, 2009 3:21
PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a
viewStack through actionscript



Hi
Wally, sorry I missed the hierarchy there. You have checkSingle on the module
and not the Viewstack. In that case, you should be able to do 
parent.parent.checkSingle
and leave out the cast as test1. So

public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a test1
which of course isn't a viewstack. But I'm not sure about this one because the
parent.parent is a module. You could also forgo using the testMod variable and
in your click declaration instead of

click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue)
/

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex apps in
the future, even though this one is not going to be a full-on huge app, I'd
learn about dispatching custom events. It's not that complicated but it takes
some time to understand. It would save some of the hassle you're trying to do
of course at the expense of a new and different kind of hassle. :-)

Michael

Wally Kolcz wrote: 



Wow...its
a 'simple' one time create app. 

All I want to do is when the user selects an answer on the question1.mxml
component, they can click a button,  pass the value of the radio button to
the test1 module's checkSingle() method  and then move to the next
question in the test1 module's stack.

When I changed the function call on the button of question1.mxml to
test1(parent).checkSingle(group1.selectedValue); mx:Button
label=Next click=test1(parent

Re: [flexcoders] Moving a viewStack through actionscript

2009-03-09 Thread Michael Wills
Hey there Wally,

You can get access to the currently selected viewstack, and also set it, 
through selectedIndex. So your initial declaration would be like
mx:ViewStack id=questionVS etc... selectedIndex=0 
click=nextQuestion()

and in your function nextQuestion you can increment the selectedIndex. 
I'd have to check but I think you can find the number of items in your 
viewStack with numChildren. That would give you your max value to finish 
your quiz or handle the end how you would like.

You can find more about what you can do with viewstacks in the docs:

http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html

Hope that helps!

Michael

Wally Kolcz wrote:

 I have a test that I want to walk through the questions using a 
 function. How can I set the inital value of the ViewStack 
 (questionsVS) to 0 and then increment it by one each time someone 
 clicks a button?

 mx:ViewStack id=questionsVS width=98% height=100% paddingLeft=10
 questions:question1 /
 questions:question2 /
 questions:question3 /
 questions:question4 /
 /mx:ViewStack

 


Re: [flexcoders] Moving a viewStack through actionscript

2009-03-09 Thread Wally Kolcz
When I added the click=nextQuestion() it was triggered off the selecting of a 
radio button and not the button. Here all the code I have. It is telling me 
that the viewStack doesn't exist when I believe it should.

test1.mxml

?xml version=1.0 encoding=utf-8?
mx:Module xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical 
width=100% height=98% xmlns:questions=com.ipexpert.questions.q1.* 
creationComplete=initApp() 
mx:Script
![CDATA[
import mx.core.Application;

public var testID:int = 1;
public var currentQuestion:int = 0;

public function initApp():void {

}

public function checkSingle(answer:Object):void {
if (answer !=0) {
Application.application.score += 1;
}
currentQuestion += 1;
nextQuestionPlease();
}

public function nextQuestionPlease():void {
}
]]
/mx:Script
mx:ViewStack id=questionsVS width=98% height=100% paddingLeft=10

questions:question1 /
questions:question2 /
questions:question3 /
questions:question4 /
/mx:ViewStack
/mx:Module

question1.mxml

?xml version=1.0 encoding=utf-8?
mx:VBox xmlns:mx=http://www.adobe.com/2006/mxml; width=98% height=98%

mx:Script
![CDATA[

import com.ipexpert.tests.test1;

public var testMod:test1 = new test1();
]]
/mx:Script

mx:Label fontWeight=bold text=1. Which layer(s) of the OSI Reference 
Model provide(s) for internetwork connectivity? /
mx:RadioButtonGroup id=group1 /
mx:RadioButton paddingLeft=10 groupName=group1 label=Data Link 
value=0 selected=true /
mx:RadioButton paddingLeft=10 groupName=group1 label=Physical 
value=0 /
mx:RadioButton paddingLeft=10 groupName=group1 label=Session 
value=0 /
mx:RadioButton paddingLeft=10 groupName=group1 label=Network 
value=1 /
mx:RadioButton paddingLeft=10 groupName=group1 label=Presentation 
value=0 /

mx:Button label=Next click=testMod.checkSingle(group1.selectedValue) /
/mx:VBox


From: Michael Wills mich...@mawills.com
Sent: Monday, March 09, 2009 10:55 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 

Hey there Wally,

You can get access to the currently selected viewstack, and also set it, 

through selectedIndex. So your initial declaration would be like

mx:ViewStack id=questionVS etc... selectedIndex=0 

click=nextQuestion()

and in your function nextQuestion you can increment the selectedIndex. 

I'd have to check but I think you can find the number of items in your 

viewStack with numChildren. That would give you your max value to finish 

your quiz or handle the end how you would like.

You can find more about what you can do with viewstacks in the docs:

http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html

Hope that helps!

Michael

Wally Kolcz wrote:



 I have a test that I want to walk through the questions using a 

 function. How can I set the inital value of the ViewStack 

 (questionsVS) to 0 and then increment it by one each time someone 

 clicks a button?



 mx:ViewStack id=questionsVS width=98% height=100% paddingLeft=10

 questions:question1 /

 questions:question2 /

 questions:question3 /

 questions:question4 /

 /mx:ViewStack



 




Re: [flexcoders] Moving a viewStack through actionscript

2009-03-09 Thread Michael Wills
If I am understanding your code correctly, you actually want to call 
test1(parent).checkSingle instead of testMod. The reason is because you 
are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of tightly 
coupled design. By that I mean, your question1 component knows about 
your test1 component. If it's a more complex app though, you may want to 
look at decoupling your app. Otherwise this app will quickly become 
inflexible and harder to maintain as it grows.

In this case, you could set up your question components to dispatch an 
event that your test1 then listens to. That way question1 doesn't have 
to be directly connected to parent.

I hope that makes sense!

Michael

Wally Kolcz wrote:

 When I added the click=nextQuestion() it was triggered off the 
 selecting of a radio button and not the button. Here all the code I 
 have. It is telling me that the viewStack doesn't exist when I believe 
 it should.

 test1.mxml

 ?xml version=1.0 encoding=utf-8?
 mx:Module xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical 
 width=100% height=98% 
 xmlns:questions=com.ipexpert.questions.q1.* 
 creationComplete=initApp() 
 mx:Script
 ![CDATA[
 import mx.core.Application;   

 public var testID:int = 1;
 public var currentQuestion:int = 0;

 public function initApp():void {

 }   

 public function checkSingle(answer:Object):void {
 if (answer !=0) {
 Application.application.score += 1;
 }
 currentQuestion += 1;
 nextQuestionPlease();
 }

 public function nextQuestionPlease():void {
 }
 ]]
 /mx:Script
 mx:ViewStack id=questionsVS width=98% height=100% 
 paddingLeft=10

 questions:question1 /
 questions:question2 /
 questions:question3 /
 questions:question4 /
 /mx:ViewStack
 /mx:Module


 question1.mxml

 ?xml version=1.0 encoding=utf-8?
 mx:VBox xmlns:mx=http://www.adobe.com/2006/mxml; width=98% 
 height=98%

 mx:Script
 ![CDATA[

 import com.ipexpert.tests.test1;

 public var testMod:test1 = new test1();
 ]]
 /mx:Script

 mx:Label fontWeight=bold text=1. Which layer(s) of the OSI 
 Reference Model provide(s) for internetwork connectivity? /
 mx:RadioButtonGroup id=group1 /
 mx:RadioButton paddingLeft=10 groupName=group1 label=Data 
 Link value=0 selected=true /
 mx:RadioButton paddingLeft=10 groupName=group1 
 label=Physical value=0 /   
 mx:RadioButton paddingLeft=10 groupName=group1 
 label=Session value=0 /   
 mx:RadioButton paddingLeft=10 groupName=group1 
 label=Network value=1 /   
 mx:RadioButton paddingLeft=10 groupName=group1 
 label=Presentation value=0 /   

 mx:Button label=Next 
 click=testMod.checkSingle(group1.selectedValue) /
 /mx:VBox

 
 *From*: Michael Wills mich...@mawills.com
 *Sent*: Monday, March 09, 2009 10:55 AM
 *To*: flexcoders@yahoogroups.com
 *Subject*: Re: [flexcoders] Moving a viewStack through actionscript

 Hey there Wally,

 You can get access to the currently selected viewstack, and also set it,
 through selectedIndex. So your initial declaration would be like
 mx:ViewStack id=questionVS etc... selectedIndex=0
 click=nextQuestion()

 and in your function nextQuestion you can increment the selectedIndex.
 I'd have to check but I think you can find the number of items in your
 viewStack with numChildren. That would give you your max value to finish
 your quiz or handle the end how you would like.

 You can find more about what you can do with viewstacks in the docs:

 http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html 
 http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html

 Hope that helps!

 Michael

 Wally Kolcz wrote:
 
  I have a test that I want to walk through the questions using a
  function. How can I set the inital value of the ViewStack
  (questionsVS) to 0 and then increment it by one each time someone
  clicks a button?
 
  mx:ViewStack id=questionsVS width=98% height=100% 
 paddingLeft=10
  questions:question1 /
  questions:question2 /
  questions:question3 /
  questions:question4 /
  /mx:ViewStack
 
 


 


Re: [flexcoders] Moving a viewStack through actionscript

2009-03-09 Thread Wally Kolcz

Wow...its a 'simple' one time create app. 

All I want to do is when the user selects an answer on the question1.mxml 
component, they can click a button,  pass the value of the radio button to the 
test1 module's checkSingle() method  and then move to the next question in the 
test1 module's stack. 

When I changed the function call on the button of question1.mxml to 
test1(parent).checkSingle(group1.selectedValue);  
mx:Button label=Next 
click=test1(parent).checkSingle(group1.selectedValue) / 

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert 
mx.containers::viewst...@6563ae1 to com.ipexpert.tests.test1.
at 
com.ipexpert.questions.q1::question1/___question1_Button1_click()[D:\wkolcz\My 
Documents\Flex Builder 
3\IPExpertBrainBuster\src\com\ipexpert\questions\q1\question1.mxml:21]

Here is checkSingle() and nextQuestionPlease()

public function checkSingle(answer:Object):void {
if (answer !=0) {
Application.application.score += 1;
}
currentQuestion += 1;
nextQuestionPlease();
}

public function nextQuestionPlease():void {

 questionsVS.selectedIndex=currentQuestion;
}



From: Michael Wills mich...@mawills.com
Sent: Monday, March 09, 2009 11:44 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript 

If I am understanding your code correctly, you actually want to call 

test1(parent).checkSingle instead of testMod. The reason is because you 

are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of tightly 

coupled design. By that I mean, your question1 component knows about 

your test1 component. If it's a more complex app though, you may want to 

look at decoupling your app. Otherwise this app will quickly become 

inflexible and harder to maintain as it grows.

In this case, you could set up your question components to dispatch an 

event that your test1 then listens to. That way question1 doesn't have 

to be directly connected to parent.

I hope that makes sense!

Michael

Wally Kolcz wrote:



 When I added the click=nextQuestion() it was triggered off the 

 selecting of a radio button and not the button. Here all the code I 

 have. It is telling me that the viewStack doesn't exist when I believe 

 it should.



 test1.mxml



 ?xml version=1.0 encoding=utf-8?

 mx:Module xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical 

 width=100% height=98% 

 xmlns:questions=com.ipexpert.questions.q1.* 

 creationComplete=initApp() 

 mx:Script

 ![CDATA[

 import mx.core.Application;   



 public var testID:int = 1;

 public var currentQuestion:int = 0;



 public function initApp():void {



 }   



 public function checkSingle(answer:Object):void {

 if (answer !=0) {

 Application.application.score += 1;

 }

 currentQuestion += 1;

 nextQuestionPlease();

 }



 public function nextQuestionPlease():void {

 }

 ]]

 /mx:Script

 mx:ViewStack id=questionsVS width=98% height=100% 

 paddingLeft=10



 questions:question1 /

 questions:question2 /

 questions:question3 /

 questions:question4 /

 /mx:ViewStack

 /mx:Module





 question1.mxml



 ?xml version=1.0 encoding=utf-8?

 mx:VBox xmlns:mx=http://www.adobe.com/2006/mxml; width=98% 

 height=98%



 mx:Script

 ![CDATA[



 import com.ipexpert.tests.test1;



 public var testMod:test1 = new test1();

 ]]

 /mx:Script



 mx:Label fontWeight=bold text=1. Which layer(s) of the OSI 

 Reference Model provide(s) for internetwork connectivity? /

 mx:RadioButtonGroup id=group1 /

 mx:RadioButton paddingLeft=10 groupName=group1 label=Data 

 Link value=0 selected=true /

 mx:RadioButton paddingLeft=10 groupName=group1 

 label=Physical value=0 /   

 mx:RadioButton paddingLeft=10 groupName=group1 

 label=Session value=0 /   

 mx:RadioButton paddingLeft=10 groupName=group1 

 label=Network value=1 /   

 mx:RadioButton paddingLeft=10 groupName=group1 

 label=Presentation value=0 /   



 mx:Button label=Next 

 click=testMod.checkSingle(group1.selectedValue) /

 /mx:VBox



 --

 *From*: Michael Wills mich...@mawills.com

 *Sent*: Monday, March

Re: [flexcoders] Moving a viewStack through actionscript

2009-03-09 Thread Michael Wills
Hi Wally, sorry I missed the hierarchy there. You have checkSingle on 
the module and not the Viewstack. In that case, you should be able to do 
parent.parent.checkSingle and leave out the cast as test1. So


public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a 
test1 which of course isn't a viewstack. But I'm not sure about this one 
because the parent.parent is a module. You could also forgo using the 
testMod variable and in your click declaration instead of


click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue) /

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex 
apps in the future, even though this one is not going to be a full-on 
huge app, I'd learn about dispatching custom events. It's not that 
complicated but it takes some time to understand. It would save some of 
the hassle you're trying to do of course at the expense of a new and 
different kind of hassle. :-)


Michael


Wally Kolcz wrote:


Wow...its a 'simple' one time create app.

All I want to do is when the user selects an answer on the 
question1.mxml component, they can click a button,  pass the value of 
the radio button to the test1 module's checkSingle() method  and then 
move to the next question in the test1 module's stack.


When I changed the function call on the button of question1.mxml to 
test1(parent).checkSingle(group1.selectedValue); mx:Button 
label=Next click=test1(parent).checkSingle(group1.selectedValue) /


I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert 
mx.containers::viewst...@6563ae1 to com.ipexpert.tests.test1.
at 
com.ipexpert.questions.q1::question1/___question1_Button1_click()[D:\wkolcz\My 
Documents\Flex Builder 
3\IPExpertBrainBuster\src\com\ipexpert\questions\q1\question1.mxml:21]


Here is checkSingle() and nextQuestionPlease()

public function checkSingle(answer:Object):void {
if (answer !=0) {
Application.application.score += 1;
}
currentQuestion += 1;
nextQuestionPlease();
}

public function nextQuestionPlease():void {
   
 questionsVS.selectedIndex=currentQuestion;

}


*From*: Michael Wills mich...@mawills.com
*Sent*: Monday, March 09, 2009 11:44 AM
*To*: flexcoders@yahoogroups.com
*Subject*: Re: [flexcoders] Moving a viewStack through actionscript

If I am understanding your code correctly, you actually want to call
test1(parent).checkSingle instead of testMod. The reason is because you
are instantiating a brand new, and unrelated, test1 component with

public var testMod:test1 = new test1();

You might be able to do

public var testMod:test1 = test1(parent);

casting the variable to the type test1.

If it's a simple app you are working on, you can do this kind of tightly
coupled design. By that I mean, your question1 component knows about
your test1 component. If it's a more complex app though, you may want to
look at decoupling your app. Otherwise this app will quickly become
inflexible and harder to maintain as it grows.

In this case, you could set up your question components to dispatch an
event that your test1 then listens to. That way question1 doesn't have
to be directly connected to parent.

I hope that makes sense!

Michael

Wally Kolcz wrote:

 When I added the click=nextQuestion() it was triggered off the
 selecting of a radio button and not the button. Here all the code I
 have. It is telling me that the viewStack doesn't exist when I believe
 it should.

 test1.mxml

 ?xml version=1.0 encoding=utf-8?
 mx:Module xmlns:mx=http://www.adobe.com/2006/mxml 
http://www.adobe.com/2006/mxml layout=vertical

 width=100% height=98%
 xmlns:questions=com.ipexpert.questions.q1.*
 creationComplete=initApp() 
 mx:Script
 ![CDATA[
 import mx.core.Application;

 public var testID:int = 1;
 public var currentQuestion:int = 0;

 public function initApp():void {

 }

 public function checkSingle(answer:Object):void {
 if (answer !=0) {
 Application.application.score += 1;
 }
 currentQuestion += 1;
 nextQuestionPlease();
 }

 public function nextQuestionPlease():void {
 }
 ]]
 /mx:Script
 mx:ViewStack id=questionsVS width=98% height=100%
 paddingLeft=10

 questions:question1 /
 questions:question2 /
 questions:question3 /
 questions:question4 /
 /mx:ViewStack
 /mx:Module


 question1.mxml

 ?xml version=1.0 encoding=utf-8?
 mx:VBox xmlns:mx=http://www.adobe.com/2006/mxml 
http://www.adobe.com/2006/mxml width=98%

 height=98%

 mx:Script
 ![CDATA[

 import com.ipexpert.tests.test1;

 public var testMod:test1 = new test1();
 ]]
 /mx:Script

 mx:Label fontWeight=bold text=1. Which layer(s) of the OSI
 Reference Model provide(s) for internetwork connectivity? /
 mx:RadioButtonGroup id=group1

RE: [flexcoders] Moving a viewStack through actionscript

2009-03-09 Thread Jim Hayes
, I'd learn about dispatching custom events. It's not that complicated
but it takes some time to understand.
 
Raising some events from the question components strikes me as being a
whole  lot easier than dealing with addressing all the different objects
through the heirarchy!
But then when I first started out with flex I didn't know that and tried
to do pretty well the same sort of thing.
You could probably google and read enough on custom events to do what
you need in an hour or two, you'd more than likely spend much more time
trying to work out your current problems than that, I'd guess.
Hth
 
-Original Message-
From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Michael Wills
Sent: 09 March 2009 22:20
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Moving a viewStack through actionscript
 
Hi Wally, sorry I missed the hierarchy there. You have checkSingle on
the module and not the Viewstack. In that case, you should be able to do
parent.parent.checkSingle and leave out the cast as test1. So

public var testMod:Object = parent.parent;

The last one failed because it was trying to convert a viewstack into a
test1 which of course isn't a viewstack. But I'm not sure about this one
because the parent.parent is a module. You could also forgo using the
testMod variable and in your click declaration instead of

click=testMod.checkSingle(group1.selectedValue)

use

click=parent.parent.checkSingle(group1.selectedValue) /

Hopefully that'll work for you.

If you have a little time to invest, and if you may be doing more Flex
apps in the future, even though this one is not going to be a full-on
huge app, I'd learn about dispatching custom events. It's not that
complicated but it takes some time to understand. It would save some of
the hassle you're trying to do of course at the expense of a new and
different kind of hassle. :-)

Michael


Wally Kolcz wrote: 
Wow...its a 'simple' one time create app. 

All I want to do is when the user selects an answer on the
question1.mxml component, they can click a button,  pass the value of
the radio button to the test1 module's checkSingle() method  and then
move to the next question in the test1 module's stack. 

__
This communication is from Primal Pictures Ltd., a company registered in 
England and Wales with registration No. 02622298 and registered office: 4th 
Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT 
registration No. 648874577.

This e-mail is confidential and may be privileged. It may be read, copied and 
used only by the intended recipient. If you have received it in error, please 
contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 
1010. Please then delete the e-mail and do not disclose its contents to any 
person.
This email has been scanned for Primal Pictures by the MessageLabs Email 
Security System.
__