Creating a function in a movie clip.

OK - so i have this method (which is in a class, if that
matters) that receives a MovieClip. I want the method to create a
function inside this movie clip and link it to the onEnterFrame
even of the movie clip.
What kind of syntax can i use for this? I'm familiar with
creating and deleting events, but not familiar with creating
functions dynamically.
Thanks for your help!

I would imagine you are trying to do something similar to
what I am doing.
I would add the onEnterFrame to your class constructor...
look at my code below...

Similar Messages

  • How do I create a play button for movie clip using AS3

    Hello.
    Bit new to this and have been searching the adobe forums and google. I am trying to create a button that will play an imported MovieClip.
    I have a movie clip that I've imported into it's own layer (Layer1) Frame 1.  I've given the MovieClip an instance name of foundationMovie.
    I've created a button and have that on its own layer(Layer2) above layer1, it is also in Frame 1.
    I've added a
    stop (); action to layer2
    The video is not set to autoplay.
    I want the video to start playing when the viewer clicks the button.  I know I've got to put some kind of event listener using AS3 in my timeline somewhere.
    I've found some code and I've been trying to work with it.  I'm sure I've mutilated it beyond usability but this is what I've got.
    stop ();
    player.addEventListener(MouseEvent.CLICK,play);
    function play(event:MouseEvent)
    gotoAndPlay("foundationMovie");
    If someone could point me the right direction or help me with my code I would really appreciate it.  Thanks.

    First, you need to clear up what you are working with... a movieclip and a video are usually entirely different things.
    Next, your code may get you started on your way with some changes.   You shouldn't use "play" as a function name due to there already being a play() method/function in Flash.
    If the movieclip is a movieclip and has an instance name of "foundationMovie", and your button has an instance name of "player" then the following adjusted code would normally work...
    stop ();
    player.addEventListener(MouseEvent.CLICK,playMovie);
    function playMovie(event:MouseEvent)
         foundationMovie.play();

  • How to create 3d effect of the movie clip on mouse move

    Dear All
    I have done the research a lot but failed I need to give the effect in flash like this
    http://www.soft.se/#/sv/portfolio/web,single,kaffeakademi
    any one know how to do that please send me any hint or peace of code so i will get an idea
    Thanks in advance

    thanks for the reply, but the carousel is the different thing. the another example http://www.bestvisualization.com/portfolio.htm click on the portfolio button to see the effect with mouse
    this is my own website but i use this portfolio executable file from some where so i need the code how can i build my own effect like this
    i need to know the code or the softwate that make this effect on mouse move
    Message was edited by: RasBilgrami

  • Create a snapshot from a movie clip

    I have put the 2 sec video clip into an iMovie event. I wish to select a part of the clip and produce a photo. How do I proceed?

    From version 10.0.6 you can share a single frame by positioning the playhead at the desired location in the timeline and selecting File - Share - Image.  A window opens asking you to choose a location for the still jpeg file.
    Geoff.

  • Moving Movie Clips dynamically

    Here's the deal. I have a function that I call to move the
    movie clips based on string that holds the movie clip instance
    name. The function as I have it now can be seen below listed under
    figure A. Figure B shows my call to that function. It takes in an
    array of strings and passes the current index to the function.
    Figure C shows my output panel text after I run the function.
    For some reason, the function is only moving one of my
    movieclips, and none of the others. I can tell this by tracing the
    instance ._x value, as shown in figure D. So, I know that my calls
    to the movieclip instances are correct, but why can I only move one
    card?? I know the movie clips are instantiated, as can be seen in
    Figure E, which show my objects list that I get from my debug menu.
    Any ideas/suggestions?

    My latest crack at it... I create multiple controllers for
    each movie clip, and I test the calling of the method by inserting
    a string literal as the call, still no luck. No matter how many
    times I call move, it will only work on the last card that I call.
    Framerate does not matter.

  • Tracking the visible property of a movie clip

    Hello,
    I am trying to track the visible property of a movie clip as
    I need to perform a function when visible = true and another when
    visible =false
    I have tried to use a listener object but I can’t get
    it to work. Can you attach a listener object to listen for the
    visible property?
    I have also tried an IF statement inside the move clip but
    this only knows the state of the ._visible when it first runs.
    I have got it to work with an onEnterFrame function on a
    movie clip inside the one I want to know the property of but I
    don’t like using the onEnterFrame as it uses a lot or
    processor speed
    Is there an easy way to track the visible property of a
    movieclip???
    Thanks
    Sam.

    > thanks for the help but the watch() method doesn't work
    for getter/setter
    > properties. is ._visible a getter/setter property?
    I was afraid of that. Yes, _visible is a getter/setter, most
    properties are. Basically watch() only works on read-only
    properties and custom variables, which is a shame.
    So I don't know of any more elegant way than constantly
    checking to see if the value changed. Centralize it and maybe
    package it in a nice class and you might feel a little better about
    it...

  • Movie clips in iDVD won't burn to disc image or a DVD

    I created an iDVD project with a slide show created in iPhoto and some movie clips I took with a digital camera that were also in iPhoto. It works great in iDVD preview. When I burn a disc image or a DVD, the movie clips don't play while the slideshow is fine. There is also the clue in the menu of the project (only on the disc image or DVD, not the iDVD preview) that the printing of the names of the movie clips is clearly lighter than the name of the slideshow. During the burning to disc or DVD, one can see the movie clips supposedly being encoded and no error messages occur. This is a birthday present. Help, please.

    It's become a moot point. It turns out that while I could navigate with the mouse with respect to the slide show (on both the disc image and the DVD I burned), I had to use the arrows and enter key to navigate and activate the movie clips. Once I figured out to use the arrow keys/enter key rather than the mouse, everything worked okay. Thanks for trying to help me!

  • Check for movie clips with AS?

    Is it possible to check if a frame contain a movie clip with
    AS, and then if movie clip is found run a function? Like a global
    "event handler " for movie clips.

    I want a function that automaticly can detect and fade in any
    movie clip found in any keyframe in the main timeline. So i don't
    have to make
    In the first keyframe in the main timeline
    on (ohh here i found a movie clip)
    //let's run a nice fade function on that movie clip
    mx.transitions.TransitionManager.start
    (eval(TheClip),
    {type:mx.transitions.Fade,
    direction:0,
    duration:1,
    easing:mx.transitions.easing.None.easeNone,
    param1:empty,
    param2:empty
    Something like that

  • Buttons and movie clips

    I'm sorry if this question has already been answered. I
    searched the archives and couldn't find what I was looking for.
    Basically what I want to do is use a button to play a movie when
    pressed. The problem is I can't figure out how to do it.
    1. I've created 3 buttoms and three movie clips.
    2. I created a layer for the background which has text on it
    that says "press to view".
    3. I created another layer for the buttons and one layer for
    the button text
    4. I created an actions layer and put a stop action in frame
    1
    5. I added another layer for the movie clips on frame 2
    (mailflow_mc), frame 3 (reject_mc), frame 4 (fullrate_mc) and
    labeled each frame accordingly.
    6. Add action script for each button:
    on (press) {
    gotoAndPlay("reject");
    When I play the movie the animations will not load and they
    flash fast. Any suggestions?
    Thanks,
    Mimi

    if you have a frame labelled reject you can use:

  • Movie Clip / Buttons

    I know this is probably something really easy to do I just
    for whatever reason cannot make this work. I am new to flash and am
    building an entire website. I used a template that I purchased and
    have been messing around with it and changing it. Problem is the
    buttons that are made are movie clips not actually buttons. I want
    to create a duplicate button, so I created a duplicate of the movie
    clip in the library. Problem is when I drag the movie clip into the
    movie and run the flash preview the new movie clips do not work
    like the other ones – meaning the other ones behave like they
    should – as a button (when I move my mouse over it the action
    works) but the new ones just appear as images. I know this must be
    a very easy fix and I must be doing something wrong. Any help would
    be greatly appreciated – (I might not have explained the
    problem accurately, so if more clarification is needed or an
    example needs to be uploaded let me know)
    Thanks a lot!!!

    Thanks that worked great, hope that wasn't too noob : (
    Well another problem as come up, I made another flash movie
    containing content in an xml file. When the swf is hosted and in
    the browser it works fine. However when i put that same swf in an
    html document and host it the xml never loads. Am i doing something
    wrong?
    Thanks in advance,
    ~Rob

  • Movie Clip Button Not Working

    I'm working on creating buttons right now as movie clips so when you roll over it they rise up. The third one "print" is jumping around like crazy and I can't figure out why. I've deleted and re-done it 3 times without luck. I've attached my file - if anyone can spot where I've made a mistake that would be great. Thanks!

    Got it - realized the text wasn't staying as static text and was a movie clip before the final frame. So if anyone else has this problem, create a new keyframe on the ending frame, and make THAT the movie clip.

  • Creating functions for movie-clips(serious problem)

    Hello,
    This is I think my third thread on these forums and in my
    previous threads I had always got some help.Well, now I have
    another serious problem, can you help me?
    I am unable to create a function that can control movie
    clips. Let me explain:-
    I have 10 movie clips on the stage and I have assigned them
    that whenever they crash to an object, they will go to a random
    position. Writing this code ten times for each movie clip would be
    very tedious, so, I thought about creating a function, but, it
    doesn't work. Here's the function, can you correct it?
    var object:movieClip;
    function position(object) {
    var testnum1:Number;
    testnum1 = random(290)+36;
    _root.object._y = -77.6;
    _root.object._x = testnum1;
    position(nameofmovieclip)
    PLEASE HELP IS REQUIRED!!!!
    Thanking All,
    Chinmaya

    Thanks for the reply,
    I tried that, it worked!
    But, now, I am encountering a really odd problem. This time
    I'll give you my full code.The problem is, that now when the object
    collides with another one, it changes its position according to the
    code but then after a while, it just passes through the object.
    Here's my code:-
    function position(object) {
    var testnum1:Number;
    testnum1 = random(290)+36;
    object._y = -77.6;
    object._x = testnum1;
    metal.onEnterFrame = function() {
    _root.metal._y += speednum;
    if (_root.metal.hitTest(_root.testline)) {
    position(_root.metal);
    speednum = random(6)+1;
    Can you help me out again,
    Thanks,
    Chinmaya
    P.S. I have tried to use the function like this:
    position(metal), but it doesn't work. And yes, I have already
    defines speednum somewhere before, so that isn't the
    problem.

  • Need help returning correct name from a code created movie clip

    Hello. I am an AS3 n00b with hopefuly a simple question I am designing a simple game in flash. This code creates an array of movie clips and asigns a picture to each one. It is a map screen. What I need is when I click on one of the created movie clips, I need it to return either the index of the clip in the array or the name of the clip. Basicaly anything I can use to tell them apart in the code. Here is the code:
    import flash.display.MovieClip;
    var MapLoader:Array = new Array();
    var strJPGext:String = ".jpg";
    var intContTileNumber:int;
    var strContTilePath:String;
    var intDistStartX:int = 63;
    var intDistStartY:int = 64;
    var intDistMultiplyY:int = 0;
    var intDistMultiplyX:int = 0;
    var intDistCount:int = 0;
    var MapSquare:Array = new Array();
    for (var i:int = 0; i < 729; i++)
             //var MapSquare:MovieClip = new MovieClip();
            MapSquare.push (new MovieClip());
            MapSquare[i].x = intDistStartX + (intDistMultiplyX * 30);
            MapSquare[i].y = intDistStartY + (intDistMultiplyY * 30);
            MapSquare[i].name = "MapSquare" + i ;
            addChild(MapSquare[i]);
            intContTileNumber = i;
            MapLoader.push (new Loader);
            strContTilePath = intContTileNumber + strJPGext;
            MapLoader[i].load(new URLRequest(strContTilePath));
            MapSquare[i].addChild(MapLoader[i]);
            intDistCount++;
            intDistMultiplyX++;
            if (intDistCount > 26){
            intDistCount = 0;
            intDistMultiplyX = 0;
            intDistMultiplyY++;
    stage.addEventListener(MouseEvent.CLICK, reportClick);
    function reportClick(event:MouseEvent):void
        trace("movieClip Instance Name = " + event.target.name);   
    Now all this works fine, it creates the map and assigns the correct picture and places them in the correct X,Y position and it is the correct grid of 27x27 squares. The problem is with the name, when I click on the movie clip, it returns "Instance2" or "Instance5" or whatever. It starts with 2 and then increases each number by 3 for each clip, so the first one is 2, then 5 then 8 and so on. This is no good. I need it to return the name that I assigned it
    . If I put the code in trace(MapSquare[1]) it will return the name "MapSquare1" so I know the name was assigned, but it isnt returning.
    Please assist
    Thanks,
    -red

    Thanks for the resopnse,
    I know I dont really need the name, I just need the index number of the array, but I cant figure out how to get the index name without specificaly coding for it. That is why in the listener event I use event.target.name because I dont know what movie clip is being clicked until it has been clicked on. Basically when a movie clip is clicked it needs to return which index of the array was clicked.
    I could do it this way:
    MapSquare[0].addEventListener(
      MouseEvent.MOUSE_UP,
      function(evt:MouseEvent):void {
        trace("I've been clicked!");
    MapSquare[1].addEventListener(
       MouseEvent.MOUSE_UP,
       function(evt:MouseEvent):void {
         trace("I've been clicked!");
    MapSquare[2].addEventListener(
       MouseEvent.MOUSE_UP,
       function(evt:MouseEvent):void {
         trace("I've been clicked!");
    ... ect
    but that is unreasonable and it kind of defeats the purpose of having the array in the first place. The code that each movie clip executes is the same, eventualy that index will be passed into a database and the data at that primary key will be retrieved and returned to the program. So I just need to know, when one of those buttons is clicked, which one was clicked and what is its index in the array.
    I am a VB programer and in VB this is very easy, the control array automatically sends its own index into the function when one of the buttons is clicked. It seems simple enough, I just dont know how to do it in action script.
    Thanks again,
    -red

  • Can you create a "constructor" for movie clips?

    What I'm doing:
    var this_array[counter] = new monster; //monster is a movie clip
    init_monster(); //set's things like .name, .x, .y, etc.
    What I want to do:
    var this_array[counter] = new monster();
    When I add a "monster"  I then call a function to "initialize" all of it's stats.
    Is there a way in the creation of the object, like with a constructor, where it automatilly does it on 1 line?
    I'm teaching myself and am a little stuck on this part.  If I have to create a "monster class" to do what I want just say so.
    Any simple examples or links to simple examples would be great. Thanks in advance.

    Ok so I've made a class Monster, and I have my movie object Red_Monster
    How would I go about creating the variable so it knows it's both?
    The only thing I can think of is linking them together as a .variable of the other.
    Example:
    var this_monster[x] = new Red_Monster();
    this_monster[x].stats = new Monster();
    It just seems a bit slopy, it would be nice to have this_monster know it's both.  Is there a way to do that?
    (added)
    I've gotten Monster to extend MovieClip, and this is working to use it as a movieclip.
    Currently trying to change the image of the movie clip in code to Red_Monster. Is there a way to do that?
    (added)
    Found how to do it, sort of.  Change the class linkage name to Monster instead of Red_Monster.  I just have to make classes for each movie clip.
    (last add, answer for anyone else)
    Ok the answer is to create a Monster class that extends MovieClip.  Then for each color_Monster they all extend Monster, no other code needed inside each class other then the constructor.

  • RemoveChild for movie clip that was added in another function?

    Hello everyone.  I have 3 different functions for my preloader.  I have an Event.OPEN, ProgressEvent.PROGRESS, and an Event.COMPLETE.  In the event.OPEN function, I create a new variable that is data typed to the class name of my preloader that I set in it's property dialogue box.  This is just a simple circle animation.  Below is my code for it:
    function addPreloader(event:Event):void
        var myPreloader:mcPreloader = new mcPreloader();
        myPreloader.x = stage.stageWidth / 2;
        myPreloader.y = stage.stageHeight / 2;
        myPreloader.width = 75;
        myPreloader.height = 75;
        addChild(myPreloader);
    My ProgressEvent.PROGRESS function looks like so:
    function preloadImages(event:ProgressEvent):void
        var percent:Number = Math.round(event.bytesLoaded / event.bytesTotal * 100);
        percent_txt.text = percent + "%";
    and my Event.COMPLETE function looks like so:
    function imageLoaded(event:Event):void
        var myLoadedImage:Loader = Loader(event.target.loader);
        addChild(myLoadedImage);
        new Tween(myLoadedImage, "alpha", Strong.easeIn, 0, 1, 0.5, true);
        event.target.loader.removeEventListener(Event.OPEN, addPreloader);
        event.target.loader.removeEventListener(ProgressEvent.PROGRESS, preloadImages);
        event.target.loader.removeEventListener(Event.COMPLETE, imageLoaded);
    The only problem is that when it's done loading, I'd like to remove the myPreloader from the stage.  Since it is declared in the Event.OPEN function, I can't communicate with it via my Event.COMPLETE function.  How can I successfully remove it from the stage after it's done loading?  Thanks!
    Jesse

    Duh, thanks Kglad.  It's been a long week ;).
    Jesse
    Date: Thu, 9 Jun 2011 13:47:57 -0600
    From: [email protected]
    To: [email protected]
    Subject: removeChild for movie clip that was added in another function?
    var myPreloader:mcPreloader
    function addPreloader(event:Event):void
       myPreloader = new mcPreloader();
        myPreloader.x = stage.stageWidth / 2;
        myPreloader.y = stage.stageHeight / 2;
        myPreloader.width = 75;
        myPreloader.height = 75;
        addChild(myPreloader);
    My ProgressEvent.PROGRESS function looks like so:
    function preloadImages(event:ProgressEvent):void
        var percent:Number = Math.round(event.bytesLoaded / event.bytesTotal * 100);
        percent_txt.text = percent + "%";
    and my Event.COMPLETE function looks like so:
    function imageLoaded(event:Event):void
    removeChild(myPreloader);
    myPreloader=null;
        var myLoadedImage:Loader = Loader(event.target.loader);
        addChild(myLoadedImage);
        new Tween(myLoadedImage, "alpha", Strong.easeIn, 0, 1, 0.5, true);
        event.target.loader.removeEventListener(Event.OPEN, addPreloader);
        event.target.loader.removeEventListener(ProgressEvent.PROGRESS, preloadImages);
        event.target.loader.removeEventListener(Event.COMPLETE, imageLoaded);
    >

Maybe you are looking for