-
1. Re: Access Variable on Main Timeline from Package
Ned Murphy Nov 11, 2014 3:23 PM (in response to TheScarecrow)Do you allow time before trying to target the main timeline? Do you pass in a reference to the main timeline when you call in the package?
-
2. Re: Access Variable on Main Timeline from Package
TheScarecrow Nov 12, 2014 5:53 AM (in response to Ned Murphy)I set the var on the main timeline at frame 1. The package is called on frame 80 on the main timeline. I am unsure of what you mean by pass reference to the main timeline when calling the package.
-
3. Re: Access Variable on Main Timeline from Package
Amy Blankenship Nov 12, 2014 8:02 AM (in response to TheScarecrow)What do you mean by "call a package"? Note that its almost never a good idea for children to know about their parents, so you may want to back up and state the larger goal. That way we can give you a solution that's better practice than what you are asking for.
-
4. Re: Access Variable on Main Timeline from Package
dmennenoh Nov 12, 2014 9:47 AM (in response to TheScarecrow)It's class, not package and it's not a good idea to mix timeline code and code in classes. One or the other - and preferably classes.
-
5. Re: Access Variable on Main Timeline from Package
TheScarecrow Nov 12, 2014 12:22 PM (in response to Amy Blankenship)OK So I have a movieclip called Assesssment5Q and it calls an AS file called Assessment5Q. The AS file loads the questions from an XML file. I need to know where they came from to load the correct questions. So I getting the label name in the main timeline and want to pass it to the Assessment5Q AS file.
-
6. Re: Re: Access Variable on Main Timeline from Package
Amy Blankenship Nov 12, 2014 1:27 PM (in response to TheScarecrow)I agree with dmennenoh that it's probably best not to mix the two, but let's start out assuming you do mix the two, and also the following
- Your instance is called assessment5Q
- You have a frame script on the same frame with the label you want to get.
Your frame script might look like:
assessment5Q.loadQuestions(currentFrameLabel);
Your Assessment5Q Class would have a method that looks like:
public function loadQuestions(label:String):void { //do your current load here }Now that your Class is set up to work from a framescript, it will work from a Document Class without modification. However, it sounds like your instance doesn't exist on frame 1 of the main timeline, so you need to make sure you don't try to reference your instance before it exists. So we're going to make use of a getter/setter pair, which will allow Flash to create your instance on the timeline per usual, but when the setter is triggered you can then do things with the new instance. Your main document code would include code something like this:
protected var _assessment5Q; public function get assessment5Q():Assessment5Q { return _assessment5Q; } public function set assessment5Q(value:Assessment5Q):void { If (_assessment5Q != value) { _assessment5Q=value; If (_assessment5Q) { _assessment5Q.loadQuestions(currentFrameLabel); } } }Note that even this better way is not a way I'd recommend if you expect your project to take longer than a couple of days to develop or be maintained over more than a couple of weeks. It's not good practice to have a single Class that has the responsibility for both getting the data and displaying it. If you only have a single question format, you may be able to get away with having a Class that loads the questions and makes questions from it. Then you can pass the loaded questions into your View as above (instead of using a method that takes a string, you can use a method that takes an array of questions).
It just so happens that I build Assessments as the vast majority of the work I do, and I have it broken down where there is a Class that has some number of Classes inside it that know how to build individual question types. That Class gets XML handed to it (from a different Class that just handles loading XML) and then it figures out which child Class knows how to build each question type and hands a snippet of XML to the appropriate child. Once all the questions are created, a set of questions will be handed into a View that can show between 1 and 9 questions. It does this by having individual question views on stage that, again, know about displaying specific types of questions. I'm not saying that you need to go whole hog into creating such a scalable design as I have. I'm just suggesting that your product is more likely to stand the test of time if you break things into smaller pieces that then cooperate. That way if the bigger pieces aren't quite right, you can put the smaller pieces together in a different way.
-
7. Re: Access Variable on Main Timeline from Package
TheScarecrow Nov 13, 2014 7:46 AM (in response to Amy Blankenship)Ok SO I may have found a different way. What I need to know is how to parse an xml file. I need to be able to display only the information from the XML file based on the variable bonusNumber = 2. How can I do that?
XML FILE:
<?xml version="1.0" encoding="utf-8"?>
<xml>
<bonus num = "1">
<questions>
<question num="1">
<questionMessage>
1. How?
</questionMessage>
<answerChoice>
1
</answerChoice>
</questoin>
</questions>
</bonus>
<bonus num = "2">
<questions>
<question num="1">
<questionMessage>
1. How?
</questionMessage>
<answerChoice>
1
</answerChoice>
</questoin>
</questions>
</bonus>
-
8. Re: Access Variable on Main Timeline from Package
Amy Blankenship Nov 13, 2014 8:09 AM (in response to TheScarecrow)Assuming that you add the closing tag and that everything between the opening and closing xml tags is in a variable called theXML, you'd find all "bonus" tags where the num attribute matches your bonusNum variable like this:
theXMLbonus(@num==bonusNum)




