?
Solved

How do I make externalInterface _global

Posted on 2010-01-05
5
Medium Priority
?
228 Views
Last Modified: 2012-05-08
Im using the externalInterface to enter som html-info in my flashmovie.
But I cant figure out how to use it outside the callback-function.
The normal way to do it would be the way shown in the code below, but that results in undefined.
It works correct if I move the line
aNum.text=_global.nNum;
inside the callback-function or simply reduce it to
aNum.text=str;

but how do I move the entered html-string/number outside the function.
import flash.external.ExternalInterface; 
ExternalInterface.addCallback("asFunc", this, asFunc); 
function asFunc(str:Number):Void {
	_global.nNum=str
}
aNum.text=_global.nNum;

Open in new window

0
Comment
Question by:petersego
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26179556
You can't.

The thing you are doing here is assigning nNum to the text before the nNum is initialised.You have to put it into the function. It should be the conventional way you do it too, is there any particular reason why you want to put the assignment out of the function?
0
 

Author Comment

by:petersego
ID: 26180000
Yes, because Im using it as a variable a lot of different places in my movie.
I have tried to place all my other code inside the function, but I cant get that to work.
Not sure why.
0
 
LVL 14

Accepted Solution

by:
TanLiHao earned 2000 total points
ID: 26187220
Hmm, if you want to use the variable passed from ExternalInterface in other places, you must make sure that the asFunc is called first. Therefore, what you should do is to wrap all your other code in a function, excluding variable initialisation that you need to have access out of the function. Then call that function when asFunc is called.

There are many ways you can do this, but it will differ depending on how you implement your code.

If you cannot get my suggestion to work, I need you to post the full source code.
0
 

Author Comment

by:petersego
ID: 26188164
Thanks, I have made a function, that delays the relevant parts of my code a couple of miliseconds.
function delay200(){
#include "mycode.as"
}
setTimeout(delay200,200);
and that works.
0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26188177
Just to tell you that hack isn't reliable everytime, because if a person's computer is extremely slow to the extent that after the delay the call back function isn't called, your code will fail. It is a very rare chance that will happen but looking at your code here's my alternative approach.

import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, asFunc);
function asFunc(str:Number):Void {
        _global.nNum=str;
        delay200();
}

function delay200(){
#include "mycode.as"
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to record live broadcast.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question