1 Replies - 4066 Views - Last Post: 16 November 2010 - 12:06 PM

#1 Guest_superyegorius*


passing parameters to swf-file

Posted 16 November 2010 - 05:44 AM

hi guys. need your help. i got a task. i got 5 flash clocks. each of them must show different time. but i need to use just one swf-file and pass there parameters from html which will correct time for each clock according to the city they are assigned. this is my action script code:

var date:Date;
addEventListener(Event.ENTER_FRAME, refreshHour);
function refreshHour(event:Event):void{
var date = new Date();
hours_mc.rotation = date.getHours()*30 + (date.getMinutes()/2) + date.getHours()*30*x;
minutes_mc.rotation = date.getMinutes()*6 + (date.getSeconds()/10);
seconds_mc.rotation = date.getSeconds()*6 + (date.getMilliseconds()/(1000/6));

as you see there is an "x" and its value i need to pass from html. what i need to write in the action-script code to claim my "x" and what in html?
and sorry for my bad english) i'm yet studing)

Is This A Good Question/Topic? 0

Replies To: passing parameters to swf-file

#2 mocker   User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: passing parameters to swf-file

Posted 16 November 2010 - 12:06 PM

To pass data from Javascript into Flash during runtime, you need to have your Flash program bind to a Javascript function:

ExternalInterface.addCallback( "jsFunction", asFunction );

ExternalInterface.addCallback documentation

This will make it so that when you call jsFunction() in Javascript, it will call asFunction() in your Flash app.

ie (in as3)
function asFunction(t:String):void {
	txtHello.text = "You entered "+t;

and in your html
function sendText() {
    var txt = prompt("Enter some text: ","");
    jsFunction( txt );
<input type="button" onclick="sendText();">

The other alternative if you only need to have Javascript set some values to initiliaze the Flash app, you can have Javascript modify the embed code for the flash object and then write it to the document. The <param> tag or attribute of your embed code is used to pass data into Flash when it loads, so in your case you could set it to the time you want the clock to show.

This post has been edited by mocker: 16 November 2010 - 12:07 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1