Thank you very much for your input. I think I understand OOP a little bit better now. You are correct in your assumtions that I have little experience coding in as3 or OOP. My background is mainly basic web- programming HTML, CSS, Javascript and php. I started a course at school a couple of weeks ago which teaches Flex and we currently using Flex Builder 3.
The reason I posted this question in this group in the first place was that my original application uses google maps and in particular markers with infowindows and customContent. But since my application is fairly big (about 200 lines, and using some custom components etc.) I decided to break the code down and try to recreate the problem I was having in my infowindows and this is how I ended up at this crossroad. I see now that the sample code I posted here was taken completly out of context and that by trying to solve the problem in my application I just created another problem for myself (actually kind of funny when I think about it). I'm going to confer with my teacher about my problem tomorrow and see if he can make any sense of it. If I don't get any answers som him (which I suspect I don't since he is also a beginner ) I will explain my problem a little better and post my code where the real issue occurs. Thanks for being so understanding and I'm sorry for wasting your time with that silly code, which was taken completly out of context. please excuse my english as it is not my first language (I'm from Norway) ;) On Sep 13, 10:23 pm, Shaun <[email protected]> wrote: > Hi Zaynt, > > You need to look into the life cycle events in flex. I > thinkhttp://www.slideshare.net/rjowen/component-life-cycleis a pretty good > walk through although its just slides basically so you might have to > do some independent research to fill yourself in on exactly what is > meant by some of the points in the slides if you don't have a strong > object oriented background. Basically the problem is as pamela > described though I modified your code inline below to show how it > would work. There are events that are fired by all UIComponents which > is the base class for pretty much all the controls (buttons, > sliders...), containers (boxes, view stacks...), anything you can add > with addChild essentially, the events are pre-initialize, initialize, > post-initialize, creationComplete and some others really but those are > the ones I tend to use the most since you generally need the component > your using to instantiate it's children or aggregate objects so you > have access to them. Like a tab navigator has a ToggleButtonBar and a > ViewStack, and when you add children to it the ViewStack has to have > been initialized or else it won't have memory allocated for it's > properties and functions yet, hence no where to store the child you're > trying to add to it. This is sort of old documentation but check out > the very bottom of this > page:http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhe... > it's got an explanation of the details of what happens to an object > when it's added how you're doing it here... well really how it happens > regardless of if you do it in MXML or AS. > > I'm guessing your not using the flex builder plugin for eclipse > because your code wouldn't compile for me... looks like you were > coming from an AS 2.0 or otherwise procedural background but what you > had almost worked, just need to wrap the code in a function and have > it occur after the application is initialized and it's children are > created. Also this is much easier to pull off in MXML this is a great > example of where MXML just makes way more sense, the code is more > descriptive visually of what you end up with in your display. I also > wrote how to do it with MXML it's best (IMO) to do as much of your UI > stuff in MXML as you can your code will end up being more concise, I > know a lot of people I work with like to push pure AS 3.0 because it > sticks to OOP better or whatever but really the flex framework was > designed [needs default constructor for objects used in MXML] to take > advantage of MXML allowing programmers to develop things more > abstractly and leave the details to the compiler (when you're making > your own extensions of UIComponent I do prefer pure AS 3.0 though)... > plus AS 3.0 is missing too much for me to consider it a robust OOP > language like Java and doesn't approach C++ in my opinion(no > overloading is one of my major peeves), but allows you to rig some > functionality to a nice view you can build quickly. > > Notice in your code you used addchild(label1) twice instead of addChild > (label2), this wouldn't happen in MXML. Ok I'm done with my spiel. > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application > xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" > creationComplete="onCreationComplete()"> > <mx:Script> > <![CDATA[ > import mx.controls.Label; > import mx.containers.HBox; > private function onCreationComplete():void > { > var label1:Label = new Label(); > label1.text = "hello world!"; > var label2:Label = new Label(); > label2.text = "how are you?"; > var cont:HBox = new HBox(); > addChild(cont); > cont.addChild(label1); > cont.addChild(label2); > } > ]]> > </mx:Script> > </mx:Application> > > Good luck, > Shaun > > ------------This is the second version look how much shorter it is you > don't even need the id property unless you want to reference it later, > the compiler will come up with an instance name for it or whatever it > needs to link to it itself------------------ > <?xml version="1.0" encoding="utf-8"?> > <mx:Application > xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute"> > <mx:HBox> > <mx:Label id="label1" text="hello world!"/> > <mx:Label id="label2" text="how are you?"/> > </mx:HBox> > </mx:Application> > > On Sep 12, 4:14 pm, Zaynt <[email protected]> wrote: > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > > layout="absolute"> > > <mx:Script> > > <![CDATA[ > > import mx.controls.Label; > > import mx.containers.HBox; > > > var label1:Label = new Label(); > > label1.text = "hello world!"; > > > var label2:Label = new Label(); > > label2.text = "how are you?"; > > > var cont:HBox = new HBox(); > > > addChild(cont); > > cont.addChild(label1); > > cont.addChild(label1); > > > ]]> > > </mx:Script> > > </mx:Application> > > > Just end up gettring: 1120: Access of undefined property label1. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API For Flash" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-maps-api-for-flash?hl=en -~----------~----~----~----~------~----~------~--~---
