Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Putting Code In A MovieClip Frames Using ActionScript.

Guest
Aug 09, 2011 Aug 09, 2011

Hello,

On the stage, I have a movie clip called mc which contains 20 frames.

I have put mc.stop(); on frame1 of the main timeline, this puts a stop action in frame1 of mc.

Now I want to put a stop(); action on frame10 of mc using the main time line where all my code is.

The code fl.getDocumentDOM().getTimeline().layers[0].frames[0].actionScript = 'stop();'; does seem to work and I don't know what to import.

There also a code method addFrameScript(0, customFunction); but it only crashes flash player.

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2011 Aug 09, 2011

Do not confuse JSFL and ActionScript - fl.getDocumentDom() is JSFL.

addFrameScript() should not crash the player - what is your code?

You can also listen to enterFrame event.

But... since you have other timeline codes in your MovieClip you added manually, you may as well add this stop() manually. Why overcomplicate?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2011 Aug 09, 2011

My full code is very long but I have not removed the imports and its already long, also note thats this is a compiled code since I am not using packages.

Im trying to use addFrameScript(); because Im nearly removing all event listeners.

Good point with the JSFL.

Yes the frame event, I have been thinking about that earlier.

And if we solved it, then in the future we will have all code on 1 frame only.

I also like to put all variable together with good name definition making code structured.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 09, 2011 Aug 09, 2011

You could do something like this from the main timeline:

mc.addEventListener(Event.ENTER_FRAME,stopShort);

function stopShort(event:Event):void {

     var thisMc:Object = event.target;

     if(thisMc.currentFrame == 10) {

          thisMc.stop();

     }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2011 Aug 09, 2011

Thats how codes on frame1 became when they got compiled, this makes sense because frame1 is considered as some function during compilation.

package bonjour_fla

{

    import adobe.utils.*;

    import flash.accessibility.*;

    import flash.desktop.*;

    import flash.display.*;

    import flash.errors.*;

    import flash.events.*;

    import flash.external.*;

    import flash.filters.*;

    import flash.geom.*;

    import flash.media.*;

    import flash.net.*;

    import flash.printing.*;

    import flash.profiler.*;

    import flash.sampler.*;

    import flash.system.*;

    import flash.text.*;

    import flash.text.engine.*;

    import flash.ui.*;

    import flash.utils.*;

    import flash.xml.*;

   

    public dynamic class MainTimeline extends flash.display.MovieClip

    {

        public function MainTimeline()

        {

            super();

            addFrameScript(0, this.frame1); // 0 is the frame number1 while frame1 is the function

            return;

        }


        function frame1():*

        {

            this.sound.load(new url request("folder/file.mp3"));

            this.sound.play();

        }

       

        public var sound:flash.media.Sound;

    }

}

I dont know what super(); does here.

I always use void, never used (*).

It never occured to me that variable goes down when compiled, now I am a bit confused about asynchronous processing.

I suppose that addFrameScript(); works with the right import but Im loss as there are numerous import and wildcards(*), it must have an import.

Im not using package in my fla file because my code becomes long with import, lines and brackets.

I don't see addFrameScript(); method in Adobe help section, I don't think using it will cause problem because I suppose all compiled codes change to package which includes the addFrameScript(); method.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2011 Aug 09, 2011

addFrameScript() is a MovieClip method so obviously you need to import MovieClip:

import flash.display.MovieClip;

It's an "undocumented" method so you won't find in a doc but it ceratnly is there - you can clearly see it in the code hint in the code editor for example.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2011 Aug 09, 2011
LATEST

The enterFrame event works as expected!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines