A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: can a new MovieClip() have parameters passed to it like a function?

  1. #1
    Member
    Join Date
    Jun 2002
    Posts
    59

    Question can a new MovieClip() have parameters passed to it like a function?

    I want to be able to call mc:myMC = new myMC([parameter1, parameter2...])

    Is that possible? Basically I want to add myMC to the stage with dynamic vars...

    Thanks for the help!

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Sure it's possible, you only need to have your class defined correctly.
    Inside myMC.as ( the class ) you should have your class constructor defined something like this:

    // you can define as many parameters as you want
    public function myMC(yourMc:MovieClip, mcName:String, mcWidth:int, mc:Height:int) { }

    And once you instantiate your class then you must do it so:

    var classInstance:myMC = new myMC(box_mc, "myBox", 200, 100);

    Be careful to feed in the correct number and type of arguments.
    Last edited by fx.barrett; 02-26-2008 at 06:20 PM.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  3. #3
    Member
    Join Date
    Jun 2002
    Posts
    59
    oh ok... so this is not possible through timeline actionscript, but rather through .as classes?

    basically what I have is an MC that has a motion tween. I want to dynamically insert different images into that MC for each tween loop. Would that be the right way to go about it?

    thanks!

  4. #4
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Well, you can use the same thing inside Flash. Simply have a function that admits parameters. Just like my example but this time you'll be loosing the access-control modifiers:

    function doSomething(yourMC:MovieClip, mcName:String):void
    {
    // do something
    }

    once you call the function with doSomething(box_mc, "myBox"); it will execute the code inside the function using the objects you fed.

    PS: in your first post, if you want to use var mc:myMC = new myMC([parameter1, parameter2...]); then myMC must be a separate class that admits N number of parameters. If myMC was the linkage name of one of your movie clips from the library then as far as I'm concern you won't be able to define custom parameters ( not without having a separate Class ).
    Last edited by fx.barrett; 02-26-2008 at 06:30 PM.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  5. #5
    Member
    Join Date
    Jun 2002
    Posts
    59
    cool thanks!

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