0

I am using the following AS code to call a javascript function which will return me the required value.

package 
{
    import flash.display.Sprite;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.MouseEvent;
    import flash.net.FileReference;
    import flash.utils.ByteArray;
    import com.adobe.images.JPGEncoder;
    import flash.external.ExternalInterface;

    public class Main extends Sprite
    {
        private var camera:Camera = Camera.getCamera();
        private var video:Video = new Video();
        private var bmd:BitmapData = new BitmapData(320,240);
        private var bmp:Bitmap;
        private var fileReference:FileReference = new FileReference();
        private var byteArray:ByteArray;
        private var jpg:JPGEncoder = new JPGEncoder();
        var id:int;





        public function Main():void
        {

            saveButton.visible = false;
            discardButton.visible = false;

            saveButton.addEventListener(MouseEvent.MOUSE_UP, saveImage);
            discardButton.addEventListener(MouseEvent.MOUSE_UP, discard);
            capture.addEventListener(MouseEvent.MOUSE_UP, captureImage);

            if (camera != null)
            {
                video.smoothing = true;
                video.attachCamera(camera);
                video.x = 140;
                video.y = 40;
                addChild(video);
            }
            else
            {
                trace("No Camera Detected");
            }
        }

        private function captureImage(e:MouseEvent):void
        {
            bmd.draw(video);
            bmp = new Bitmap(bmd);
            bmp.x = 140;
            bmp.y = 40;
            addChild(bmp);

            capture.visible = false;
            saveButton.visible = true;
            discardButton.visible = true;
        }

        private function saveImage(e:MouseEvent):void
        {
            byteArray = jpg.encode(bmd);
            id=ExternalInterface.call("getID()");

            fileReference.save(byteArray, id+".jpg");

            removeChild(bmp);
            saveButton.visible = false;
            discardButton.visible = false;
            capture.visible = true;
        }

        private function discard(e:MouseEvent):void
        {
            removeChild(bmp);
            saveButton.visible = false;
            discardButton.visible = false;
            capture.visible = true;
        }
    }
}

However when the function is called , it seems it is returning me a 0 always ,,,,, tried hard to understand the issue , but i guess i am not able to figure it out.I tried to alert the value returned by javascript function , it is proper,

function getID() {

    var idno = $('#ctl00_ContentPlaceHolder1_memberidcam').val();
    alert(idno);
    return idno;

}

Please somebody help me. Thanks

2 Answers 2

2

Check your AllowScriptAccess parameter from the embed code. It influences whether the swf is permitted to interact with JS through ExternalInterface:

http://helpx.adobe.com/flash/kb/control-access-scripts-host-web.html

Also, best practice would be to check if ExternalInterface is available:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#available

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

2 Comments

,,, i tried it but still i cant figure it out,,,, badly stuggling with this....Thanks for your interest
Finally after hours of struggle ,, i got it working ,,, the issue here was i was calling the javascript method this way id=ExternalInterface.call("getID()"); i dont know why but that was the issue , i changed it to following and it worked for me id=ExternalInterface.call("getID");
2

It could be an issue with the type you are returning from your JavaScript. The val() method is probably just returning a string.

So try changing your JavaScript to convert the value to an integer:

function getID() {
    var idno = $('#ctl00_ContentPlaceHolder1_memberidcam').val();
    return parseInt(idno);
}

1 Comment

you might also want to look at this question stackoverflow.com/questions/701200/…

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.