Confusing,how Context is initialised for Flash and Flex?

saumya's Avatar

saumya

08 Jun, 2010 06:52 AM

Hi,
I just finished my HelloWorld ActionScript application. While trying the same thing in Flex, I tried

// Manually add something to stage contextView.addChild(new MyViewMXML());

in my context and it never compiles(as expected),saying addchild is not possible(which is valid.)

Again, while writing the Context Class, in Flash application, the constructor takes a "DisplayObjectContainer" as an arguement,while for Flex Example application,which ships with the RobotLegs, there is nothing passed in as an arguement.
Just thinking of what is actually going on on these situations,any light on these ares will be very helpful
thanks
saumya

  1. 2 Posted by Jason Dias on 08 Jun, 2010 07:04 AM

    Jason Dias's Avatar

    not pretty but you could do this
    `(contextView as Container).rawChildren.addChild()`

  2. 3 Posted by saumya on 08 Jun, 2010 07:25 AM

    saumya's Avatar

    thanks Jason,
    but I am trying to understand whats going on under the hood. I mean, what I am understanding is correct or I am going wrong altogether!!
    Why the constructor is not taking up values in case of a Flex Application and why its taking for Flash App! Or its the way and I have to go by that.

  3. 4 Posted by saumya on 08 Jun, 2010 10:49 AM

    saumya's Avatar

    while trying

    <robotLegs:HelloRobotLegsAirContext contextView="{this}"/>

    in my entry point, FlashBuilder says

    'HelloRobotLegsAirContext' declaration must be contained within the tag, since it is not assignable to the default property's type 'Array' or element type 'mx.core.IVisualElement'. HelloRobotLegsAIR.mxml /HelloRobotLegsAIR/src line 10 Flex Problem

  4. 5 Posted by tom on 08 Jun, 2010 11:26 AM

    tom's Avatar
    <fx:Declarations>
        <robotLegs:HelloRobotLegsAirContext contextView="{this}"/>
    </fx:Declarations>
    

    should do the trick.

  5. 6 Posted by saumya on 08 Jun, 2010 11:36 AM

    saumya's Avatar

    ya tom,thanks. exactly that does the trick.
    But now I am stuck again in the next step.
    In my contaxt I have put something like this
    //Adding the view to stage this.contextView.addChild(new HomeView());

    Now it throws error at run time(which is a valid error )
    Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.

    Probably I am following along with actionscript project to here, so the confusion. But then how to go about it.
    thanks

  6. 7 Posted by tom on 08 Jun, 2010 11:47 AM

    tom's Avatar

    you actually need to call addElement() as the message suggests.
    on a quick search on "addElement" in the discussions i came up with
    http://knowledge.robotlegs.org/discussions/problems/33-contextviewa...
    http://knowledge.robotlegs.org/discussions/problems/66-cant-get-an-...

  7. 8 Posted by saumya on 08 Jun, 2010 11:51 AM

    saumya's Avatar

    Thanks tom, first tried them but Flashbuilder showed up compile time error up-front as addElement is not present in the context.
    I am currently going through the links you provided above.

  8. 9 Posted by saumya on 08 Jun, 2010 11:58 AM

    saumya's Avatar

    Awesome,tom.The first link

    http://knowledge.robotlegs.org/discussions/problems/33-contextviewa...

    works like a charm.
    Now I am feeling, whether this is the way to go in a Flex4 Application?! I mean is it the best way to do this stuff.

    Now let me go through the second link. :) I am happy that it is working now.

  9. 10 Posted by saumya on 08 Jun, 2010 12:23 PM

    saumya's Avatar

    Well,I am somewhat ok with the typecasting and adding it to the stage. For I have tested it with the mediator and a simple event,everything works.
    Just wondering, what is the recommended way to add a view and remove a view from the stage in a Flex4 application.

    I must say, the community here is very active and supportive. Good work people, thanks a lot.

  10. 11 Posted by tom on 08 Jun, 2010 12:33 PM

    tom's Avatar

    do you really need to add and remove visual children? in many cases it works sufficiently well to toggle their visibility instead of removing them.
    if you need to i'd recommend handling children by a mediator. i.e. declare a container in the mediated view to add and remove them there. of course, you can just use the context view.

  11. 12 Posted by saumya on 08 Jun, 2010 12:44 PM

    saumya's Avatar

    Thanks tom.
    I am going ahead with my first application with toggling views.
    The question actually, when some part of my application(say a module) is over and I want to remove it completely,I do not need that anymore. How that is done ? (Do I need to remove it from the context view? and what about its mediator,I must get that out too.)

  12. 13 Posted by tom on 08 Jun, 2010 01:07 PM

    tom's Avatar

    i do strongly recommend that you get used to the robotlegs basics first, things will feel a lot easier after some days.
    if you really need modules have a look at http://github.com/Stray/robotlegs-utilities-Modular

  13. 14 Posted by saumya on 08 Jun, 2010 06:22 PM

    saumya's Avatar

    Thanks tom.
    Will be putting up an application with it and going through the modules docs.

  14. Support Staff 15 Posted by Joel Hooks on 08 Jun, 2010 06:29 PM

    Joel Hooks's Avatar

    http://github.com/joelhooks/robotlegs-utilities-Modular

    I'd recommend this fork if you are using Robotlegs 1.1 and/or Flex.

  15. 16 Posted by tom on 08 Jun, 2010 06:33 PM

    tom's Avatar

    of course, my fault. btw, any reason why the forks have not been merged?

  16. 17 Posted by saumya on 08 Jun, 2010 06:41 PM

    saumya's Avatar

    Thanks Joel.
    And loving this community,so much activeness and already falling in love with robotlegs. Just thinking,will finish an application first and will comeback again.
    you guys are cool.

  17. 18 Posted by Stray on 08 Jun, 2010 07:19 PM

    Stray's Avatar

    Yes... in a nut shell I'm still using the old fork in production on a major app - and it works great.

    I'm not 100% sure that the refactor to Joel's fork would be pain-free... in fact I think it would break a lot of my existing approach, so I'm waiting until I've got time on my hands to implement Joel's revision, see how much stuff breaks and what fixes are required and then merge.

    Small examples are useful, but I had to make some changes between the version of modular that worked for my original small example and the version that works for a full on modular application, so I'm hanging back until I've actually put the new 1.1 version through its paces.

    I'll add a note to the ReadMe to help people pick the right fork.

  18. 19 Posted by saumya on 08 Jun, 2010 07:26 PM

    saumya's Avatar

    That would be a great help for starters with robotlegs like me.

  19. Stray closed this discussion on 12 Feb, 2011 01:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac