Note that there are some explanatory texts on larger screens.

plurals
  1. POpass the variable from one swf to another actionscript file?
    primarykey
    data
    text
    <p>I'm trying to pass a variable from my main swf to another one that's being loaded in a container in the main swf.I follow this <a href="https://stackoverflow.com/questions/7964347/how-to-pass-variable-from-swf-file-to-as-file">Link</a>,Its Working Fine,My problem is, if i declared the variable within the function i Cannot Access the Variable.AnyBody Help me (Sorry for Big Coding) My Coding My a.swf coding</p> <pre><code> import flash.display.LoaderInfo; import flash.display.Sprite; import flash.text.TextField; import flash.text.Font; var nc:NetConnection = null; var textchat_so:SharedObject = null; var lastChatId:Number = 0; var chatSharedObjectName:String = "textchat";//i can access this variable var chatText:String = ""; var mcCtr:int = 0; var align:String="gh"; var msg:String;// i cannot access this variable listChat.visible = false; var tickerIdx:int = 0 { nc = new NetConnection(); nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus); trace("connect: "+ "xxx"); trace("connect: "+ "xxx"); //chatSharedObjectName = connect.soNameStr.text; nc.connect("xxx"); } function ncOnStatus(infoObject:NetStatusEvent) { trace("nc: "+infoObject.info.code+" ("+infoObject.info.description+")"); if (infoObject.info.code == "NetConnection.Connect.Success") { initSharedObject(chatSharedObjectName); } } // format the text chat messages function formatMessage(chatData:Object) { trace("room"+chatData.txtalign); var number:String = chatData.user; align=chatData.txtalign; var myFormat:TextFormat = new TextFormat(); myFormat.size =(chatData.txtsize); var tf:MarqueeTextField = new MarqueeTextField(); myFormat.font=chatData.txtfont; tf.maxChars=100; tf.text =chatData.message ; tf.textColor = chatData.user; // &lt;---------------------------------- tf.defaultTextFormat=myFormat; //tf.width = stage.stageWidth / 2; tf.width = stage.stageWidth; tf.height = stage.stageHeight if(chatData.txtalign=="Left") { tf.autoSize ="left"; } if(chatData.txtalign=="Right") { tf.autoSize = "right"; } //tf.x = tf.y = 100; //trace(stage.stageWidth); if( listChat.numChildren &gt;= 0 ) { //listChat.removeChildAt( 0 ); } listChat.visible=true; listChat.addChild(tf); var t:Timer = new Timer(chatData.txtspeed); t.addEventListener( TimerEvent.TIMER, function(ev:TimerEvent): void { tf.text =tf.text.substr(1) + tf.text.charAt(0); } ); t.start(); if(listChat!=null) for (var i:int = listChat.numChildren-2; i &gt;= 0; i--) { listChat.removeChildAt (i); } msg=chatData.txtalign; return msg; } function syncEventHandler(ev:SyncEvent) { var infoObj:Object = ev.changeList; // if first time only show last 4 messages in the list if (lastChatId == 0) { lastChatId = Number(textchat_so.data["lastChatId"]) - 1; if (lastChatId &lt; 0) lastChatId = 0; } // show new messasges var currChatId = Number(textchat_so.data["lastChatId"]); // if there are new messages to display if (currChatId &gt; 0) { var i:Number; for(i=(lastChatId+1);i&lt;=currChatId;i++) { if (textchat_so.data["chatData"+i] != undefined) { var chatMessage:Object = textchat_so.data["chatData"+i]; formatMessage(chatMessage); chatText += "&lt;p&gt;" + msg + "&lt;/p&gt;"; trace(msg); //listChat.htmlText = chatText; } } if (listChat.length &gt; 0) listChat.verticalScrollPosition = listChat.maxVerticalScrollPosition; lastChatId = currChatId; } } function connectSharedObject(soName:String) { textchat_so = SharedObject.getRemote(soName, nc.uri); // add new message to the chat box as they come in textchat_so.addEventListener(SyncEvent.SYNC, syncEventHandler); textchat_so.connect(nc); } function connectSharedObjectRes(soName:String) { connectSharedObject(soName); trace(soName); } function initSharedObject(soName:String) { // initialize the shared object server side nc.call("initSharedObject", new Responder(connectSharedObjectRes), soName); } </code></pre> <blockquote> <p>i Want to access the variable inside the function(formatMessage) from b.as</p> </blockquote> <p>I can Load the a.swf in b.as here my Coding b.as</p> <pre><code>private function addMessage(){ _loader = new Loader(); _loader.x=10; _loader.y=200; _loader.load(new URLRequest("a.swf")); _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad); function onLoad(evt:Event):void { var target:DisplayObject = LoaderInfo(evt.target).content as DisplayObject; trace(target["msg"]);// here it return null value } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload