A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: targeting Sprite as MovieClip(parent)

  1. #1
    Senior Member
    Join Date
    May 2000
    Posts
    135

    targeting Sprite as MovieClip(parent)

    I have a MC1 with a comp.as class file
    I have a MC2 with a object.as class file

    - MC1 has all variables for the animation. It creates a number of MC2 children.

    For some reason I can only use MovieClip(parent).somevariable in MC2 if I set the comp.as class file to package as "MovieClip" instead of "Sprite".

    But that makes MC1 loop 2 frames nonstop.

    Anybody knows how to call upon a Sprite as parent?
    P

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Use Sprite(parent) instead of MovieClip(parent). What properties of a Sprite or MovieClip are you using that you need to cast parent in the first place? If it's the variables you've defined, then you should cast to the comp class instead.

  3. #3
    Senior Member
    Join Date
    May 2000
    Posts
    135
    testing, doesn't work.

    trace(Sprite(parent).hor) gives an error

    1119: Access of possibly undefined property hor through a reference with static type flash.display:Sprite.

    MC1 has a variable "hor", numeric. Every MC2 child draws a shape and has to move it the distance "hor" pixels over a period of say e.g. 48 frames.

    P

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That's exactly why I said that if it's the variables you've defined in the comp.as file that you need access to you should cast to comp instead.

    comp(parent).hor

    Casting is the process of telling as3 that a variable of one type is actually of another type. The type of parent is DisplayObjectContainer, so in order to use things that are specific to a different type, such as MovieClip, Sprite, or comp, you have to cast.

  5. #5
    Senior Member
    Join Date
    May 2000
    Posts
    135
    aaah, indeed comp(parent).hor worked

    tnx man. I knew there must be some simple way. I'm used to AS2 and simply using _parent will work fine. Still getting used to AS3 and new syntax stuff and class files. I'm just digging into external .as files and wasn't aware you could call the class file name this way.

    What I can figure out is why it's comp(parent).hor and not comp.hor
    Snouldn't comp. be sufficient without the parent?

    P.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Quote Originally Posted by patrickjv
    aaah, indeed comp(parent).hor worked
    What I can['t] figure out is why it's comp(parent).hor and not comp.hor
    Snouldn't comp. be sufficient without the parent?
    Nope. comp is a class, not an instance. The hor property defined in comp applies to each instance of a comp. You could have defined it to apply to the class itself by using the static keyword, in which case comp.hor would have worked, but there would be only a single hor for all comps. And as any pimp knows, a single hor ain't much.

  7. #7
    Senior Member
    Join Date
    May 2000
    Posts
    135
    I see, well.. whatever works I'll take it any time. Glad to see I can continue without having to push a duplicate to every MC2 child from the comp.as script, that would make so much redundant garbage variable. Extracting from, like I now can, is so much more efficient

    Quote Originally Posted by 5TonsOfFlax
    And as any pimp knows, a single hor ain't much.
    LOL, and so many comps to take care off, hehe

    tnx again
    P.

  8. #8
    Senior Member
    Join Date
    May 2000
    Posts
    135
    darn... i did something and suddenly it's not working anymore. The moment I use comp.(parent).hor I get

    TypeError: Error #1034: Type Coercion failed: cannot convert classes.dollar::comp@3a260b1 to comp.

    Now I can't figure out what I did, pulling my hair out with frustration
    I was testing component shim implementation so maybe that did something weird

    any clue?
    P

  9. #9
    Senior Member
    Join Date
    May 2000
    Posts
    135
    so weird
    the comp.as and object.as files were both in subfolders of the folder where the .fla resides, namely in /classes/dollar/

    So I tried classes.dollar.comp(parent).hor instead of comp(parent).hor and voila it worked again.

    Any clue why it worked before? they were in that folder the whole time and it worked right away after your sugestion. Anything to do with 'private' or 'public' or "export in first frame" or anything else I'm missing?

    P.

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    could be a classpath issue. I'm not that familiar with component shim though. If you declared each to be in the classes.dollar package, you shouldn't have had to use the fully qualified name. But I don't really know for sure.

  11. #11
    Senior Member
    Join Date
    Jan 2008
    Posts
    150
    comp.(parent).hor
    and
    classes.dollar.comp(parent).hor

    have one little difference that you would easily overlook:
    comp.(parent).hor is not the same as comp(parent).hor
    ???
    you've got an extra "dot" in thar.


    I learned to cast things in the
    Code:
    some_class_object:sprite //I'm just including this line to show that the variable is being stored as something it extended or whatev
    this.(some_class_object as some_class).some_function();
    format, which I find a bit easier to read. I don't think there's a functional difference so it's just a stylistic option.
    Last edited by Shokushu; 01-26-2008 at 11:23 PM.

  12. #12
    Senior Member
    Join Date
    May 2000
    Posts
    135
    the extra dot was a typo. Still haven't figured it out though... but as long as complete folder path works I won't complain anmymore, ha.

    Got different things to worry about, like why the heck the component Avatar movieclip is not hiding on ctr-test ... a whole new posting maybe.
    P.

  13. #13
    Senior Member
    Join Date
    May 2000
    Posts
    135
    New info: I created a whole new folder for everything and started more or less from scratch, that solved the "path" issue in .as file. Makes no sense but it did. Can use comp(parent).hor now

    New issue:
    Instead of placing a component in a keyframe, I'm testing out by AS.
    Should frame script
    Code:
    var child = new classes.dollar.comp();
    addChild(child);
    work? It gives me a 1120: Access of undefined property classes.
    Another something simple I'm doing wrong?
    P.

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