There is one software named Maxedia. We can play .swf files in it for live text change, etc. But it has its own limitations. As for now we can not use mouse event in it. I am providing you a working sample file. It is a very simple project. When we connect it with Maxedia web server it provide us one text input field option. The input text is than display in Maxedia output window. The code is divided in two parts - Outer and Inner script. Outer script is for the main Scene and inner script is for text movie clips.
OUTER SCRIPT CODE:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("GetVars",GetVars);
ExternalInterface.addCallback("SetVariable1",SetVariable1);
function GetVars():Array
{
return [
{VariableName:"SetVariable1",DefaultValue:"Variable1"}
]
}
function SetVariable1(variable:String):void
{
for(var i:int = 0; i < numChildren; i++)
{
var mc:MovieClip = getChildAt(i) as MovieClip;
if(mc != null && mc.name == 'TitleAnimation')
{
mc.variable1 = variable;
mc.SetVariable1(variable);
}
}
}
INNER SCRIPT CODE:
function SetVariable1(variable:String):void
{
if(variable != null)
{
for(var i:int = 0; i < numChildren; i++)
{
var mc:MovieClip = getChildAt(i) as MovieClip;
if(mc != null && mc.name == 'Text1')
{
var object:TextField = mc.getChildByName('InputTextField1') as TextField;
if(object != null)
{
object.text = variable;
}
}
}
}
}
SetVariable1(this.variable1);
Now what I need to do is, instead of getting Text as a output I want it to perform some action. For e.g. if I type numeric character "1" in the input text field and press the Enter key it should display Picture 1 and if I type 2 it should display Picture.
Please let me know if any further information is required at my end. This is a very important project for me and I truly appriciate the way your helped and helping me. Many thanks.
The code you just showed does nothing to explain what you are trying to do with the code you started off with. The errors/problems are likely due to a couple of reasons. Part of the proplem was likely due to not assigning a value to the picVisible variable at the beginning. The other part of the problem was likely due to setting the picVisible value to the object you wanted to fade in before you did the fade out, which was fading out the object that was not yet visible.
I have rewritten the code so that it functions properly for what I am hoping your intentions are. I made it so that if Pic1 is showing, entering a 1 will do nothing, same for Pic2.
import flash.events.Event;
import flash.events.KeyboardEvent;
import fl.transitions.*;
import fl.transitions.easing.*;
import fl.motion.*;
import fl.transitions.TweenEvent;
InputText.addEventListener(KeyboardEvent.KEY_DOWN, inputFieldHandler);
var Pic1:Picture1 = new Picture1();
var Pic2:Picture2 = new Picture2();
var picToShow:* = Pic1;
Pic1.x = Pic2.x = 800;
Pic1.y = Pic2.y = 500;
Pic1.alpha = 1;
Pic2.alpha = 0;
addChild(Pic1);
addChild(Pic2);
function inputFieldHandler(event:KeyboardEvent) {
if (event.keyCode == Keyboard.ENTER) {
var iText:String = InputText.text;
var picToHide:* = picToShow;
var okayToShow:Boolean = false;
if ((iText == "1" || iText.toLowerCase() == "one") && picToHide != Pic1) {
picToShow = Pic1;
okayToShow = true;
} else if ((iText == "2" || iText.toLowerCase() == "two") && picToHide != Pic2 ) {
picToShow = Pic2;
okayToShow = true;
}
if(okayToShow){
InputText.removeEventListener(KeyboardEvent.KEY_DOWN, inputFieldHandler);
var PicOut:Tween = new Tween(picToHide,"alpha",Strong.easeOut,picToHide.alpha,0,1,true);
PicOut.addEventListener(TweenEvent.MOTION_FINISH, PICON);
}
}
}
function PICON(event:TweenEvent):void {
var PicIn:Tween = new Tween(picToShow,"alpha",Strong.easeOut,picToShow.alpha,1,1,true);
PicIn.addEventListener(TweenEvent.MOTION_FINISH, resetInputField);
}
function resetInputField(event:TweenEvent):void {
InputText.addEventListener(KeyboardEvent.KEY_DOWN, inputFieldHandler);
}