mnio112233
mnio112233

Reputation: 63

Set text into clipboard from flashVars

What i want to do: Get Flash Var, Set flashVar Into ClipBoard.
Html:

<embed src="setClip.swf" FlashVars="res=123" quality="high" TYPE="application/x-shockwave-flash">

action script(3):

function loaderComplete(myEvent:Event)
{
   this.flashVars=this.loaderInfo.parameters;
   this.flashVarsLoaded=true;
   this.useFlashVars();
}
function useFlashVars()
{
        aaa.text = myFlashVars.res;
}
var myFlashVars=new Object();
myFlashVars.flashVarsLoaded=false;
myFlashVars.loaderComplete=loaderComplete;
myFlashVars.useFlashVars=useFlashVars;
this.loaderInfo.addEventListener(Event.COMPLETE, myFlashVars.loaderComplete);

When i open the html page there is no text in "aaa" input.
What is the best way to get flash var and then insert him into clipboard(as1,as2,as3)(I Need Good Example)?

Upvotes: 1

Views: 318

Answers (1)

Smolniy
Smolniy

Reputation: 456

You not need to wait flashvars loading and use Event.COMPLETE. Flashvars lays in main class loaderInfo.parameters just when player starts. Just try trace it trace (this.loaderInfo.parameters["res"]) in main class.

1 create new fla file, save it

2 add to stage textfield (dynamic), set instance name ft1

3 click main stage, in properties panel, Class type main

4 create main.as in dir with fla (step 1)

5 main as:

package  {

    import flash.display.MovieClip;
    public class main extends MovieClip {
        public function main() {
            tf1.text = this.loaderInfo.parameters["foo"];
        }
    }
}

6 File->publish

7 Go dir (step 1), open .html file, add line <param name="flashvars" value="foo=10" /> in params (twice)

8 open HTML in browser, enjoy

(NB: You cannot test flashvars in Adobe Flash IDE environment, olny in real browser)

About clipboard: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/System.html#setClipboard() This method works from any security context when called as a result of a user event (such as a keyboard or input device event handler).

9 add button to stage, name it btn

10 main.as:

package  {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.system.System;

    public class main extends MovieClip {
        public function main() {
            tf1.text = loaderInfo.parameters["foo"];
            btn.addEventListener(MouseEvent.CLICK, onClickHandler);
        }

        private function onClickHandler(e:MouseEvent):void {
            System.setClipboard(loaderInfo.parameters["foo"]);
        }
    }
}

11 Compile .fla, open HTML in browser, click btn, check clipboard

Sorry, no way to fill clipboard "automagically" without user interaction. Remember: reading and writing the clipboard is a huge security hole.

Upvotes: 1

Related Questions