A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: self-reference on MXML method call

  1. #1
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625

    self-reference on MXML method call

    How do you self-referenciate a component in MXML when calling ad AS inline function?


    Code:
    <mx:Script>
    function fadeIn(canvas:Canvas)
    {
        trace(canvas);
    }
    </mx:Script>
    <mx:Canvas show="fadeIn(this)"></mx:Canvas>
    The previous code will throw an error, because "this" is a reference to the root of the MXML document, which is in my case the Application.

    Is there any way to quickly pass a self reference? Or do I have to pass an ID and look for the corresponding object from within the function?
    Altruism does not exist. Sustainability must be made profitable.

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    To be honest, a lot of these questions are more fitting for the AS3 forum as they aren't really specific to Flex other than the fact they are compiled with it. Senocular is the most capable with straight AS3 using the SDK compiler.

    Since in this one I see you've placed a canvas onstage using Flex , I would most likely go about reusing an effect differently than how a straight AS3 scripter might using standard mxml.

    This being one of many ways I could do it and make the effect specific to what I want to fade

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>

    [Bindable]
    public var foo:String;

    </mx:Script>

    <mx:Fade id="fadeOut" target="{foo}" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
    <mx:Fade id="fadeIn" target="{foo}" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>

    <mx:Canvas id="aa" visible="{cb1.selected}" hideEffect="{fadeOut}" showEffect="{fadeIn}" backgroundColor="#000080" width="68" height="57" x="78" y="83"/>
    <mx:Canvas id="bb" visible="{cb2.selected}" hideEffect="{fadeOut}" showEffect="{fadeIn}" backgroundColor="#ff0000" width="68" height="57" x="298" y="83"/>

    <mx:CheckBox id="cb2" label="visible" selected="true" change="foo='bb';" y="148" x="298"/>

    <mx:CheckBox id="cb1" label="visible" selected="true" change="foo='aa';" y="148" x="78"/>

    </mx:Application>


    I don't even have use the showEffect/hideEffect properties (I personally would not and would always initiate it myself...especially if I script something to be hidden on creationComplete and don't want the effect fired because it's bound) but could push it with "foo='something';fadeIn.play()" etc etc. We both would accomplish the same thing but how we use Flex might predicate how we do it. In here we mainly focus on Flex Builder with AS3 complimentary to MXML and in AS3 they focus on AS3 being dominate

  3. #3
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    well yes, as you can see I'm an old-fashioned Flash developer.
    I actually just flew from PP to OOP just a few months ago, and found my self stuck without Flex.

    Fact is, I hate that my semi-finished application was 35Kb with most of the UI (excluding images, which would build for another 55Kb), and now with Flex I start from a 150Kb with a couple objects.....
    But as it is I can't afford spending 6 months developing my own optimized UI elements in Flash, so I have to stick with the ready made ones.

    Thanks for the info on the Flex style. It does make things much easier.
    Altruism does not exist. Sustainability must be made profitable.

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    That's what kind of surprised me about the progressBar question. I know you build your own stuff with AS3 and just couldn't see you using a progressBar component and driving your file size up.

    Most people I see scripting progress with AS3 are using some hand built visual indicator bound to the progressEvent and definitely saving size

  5. #5
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    You're right, in fact I didn't think about that in the beginning.
    Again, I'm used to the old workaround: a separate preloader movie (which I would manage to keep below 10K with graphics) that would do the loading and then re-load the main movie on top of itself.
    Altruism does not exist. Sustainability must be made profitable.

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    I recall Jesse Warden ( or one of the gurus) playing around with different progress routines. Try a google for "AS3 progressBar" and they should turn up

  7. #7
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Thanks but I'm quite well packed with AS3 now, my problem was about implementing components through classes (and not through AS components).

    Altruism does not exist. Sustainability must be made profitable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center