0

I have an an class a fla called draw.fla . The document class associated with draw is Draw.as The code inside Draw.as is as follows

package
{
import flash.display.MovieClip;
import flash.display.Graphics;

public class Draw extends MovieClip
{
    public  function drawCircle1(color:Number):void
    {
        graphics.beginFill(color);
        graphics.drawCircle(100,100,40);
        graphics.endFill();
    }

}
}

The resulting swf is called draw.swf.

I have another fla called test.fla.

The following is the code on the first frame on the main time line.

import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Loader;

var swfLoader = new Loader();
var color:Number;

color = Math.round(Math.random()*0xFFFFFF);
var urlReq:URLRequest = new URLRequest("draw.swf");
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadComplete);
swfLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, swfLoadError);
swfLoader.load(urlReq);

function swfLoadComplete(evt:Event):void
{
    var loader:Loader = Loader(evt.target.loader);
    addChild(loader.content);
    swfLoader.removeEventListener(Event.COMPLETE, swfLoadComplete);
}

function swfLoadError(evt:IOErrorEvent):void
{
  trace("Unable to load swf ");
  swfLoader.removeEventListener(IOErrorEvent.IO_ERROR, swfLoadError);
}

I have loaded dwaw.swf into test.swf as you can see. Is there anyway I can access the drawCircle1 function of Draw from the test.fla. Actually I need to pass the value color as an argument while accessing this function.

2 Answers 2

3

If I'm not wrong, once the loader is complete you could simply make MovieClip(loader.content).drawCircle1(0xFF0000);.

Sign up to request clarification or add additional context in comments.

Comments

1

Loader.content should be that class, and function can be called by name with square bracket syntax:

function swfLoadComplete(evt:Event):void
{
    var loader:Loader = Loader(evt.target.loader);
    addChild(loader.content);

    //trying to call function drawCircle1
    loader.content["drawCircle1"](0xFF0000);

    swfLoader.removeEventListener(Event.COMPLETE, swfLoadComplete);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.