Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:11:41+00:00 2026-05-26T14:11:41+00:00

I’m trying to pass a variable from my main swf to another one that’s

  • 0

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 Link,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

 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; // <----------------------------------
 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 >= 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 >= 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 < 0)
        lastChatId = 0;
}

// show new messasges
var currChatId = Number(textchat_so.data["lastChatId"]);

// if there are new messages to display
if (currChatId > 0)
{
    var i:Number;
    for(i=(lastChatId+1);i<=currChatId;i++)
    {
        if (textchat_so.data["chatData"+i] != undefined)
        {
            var chatMessage:Object = textchat_so.data["chatData"+i];

             formatMessage(chatMessage);


        chatText += "<p>" + msg + "</p>";
        trace(msg);
            //listChat.htmlText = chatText;
        }
    }

    if (listChat.length > 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);

}

i Want to access the variable inside the function(formatMessage) from b.as

I can Load the a.swf in b.as here my Coding
b.as

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
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:11:41+00:00Added an answer on May 26, 2026 at 2:11 pm

    I can’t understand some slice of your code.

    • Param of Message function isn’t a variable and it’s call like function name.
    • You variable msg should be public
    • Your function Message don’t have a specific return value
    • Message(Message); This has no sense!

    So, I don’t know how your application work but I fix your code as follow:

     public var msg:String = "";
     function Message(msg:String):void
     {
         this.msg = msg;// Here you assign directly the message
         trace(this.msg);
     }
    

    In the loader code if you want access to msg variable your code should work fine.

    Tip: You should use classes concat to your swfs and work with public method for access to these variables. If you have problems you could post more of your code to be more accurate.

    I hope this will be usefull to you!

    UPDATE:
    I repeat, I don’t know much about how your application is structured, I’d do as follow:

    1. Specific in Adobe Flash a document class for your fla project, for example main.as
    2. Create another Adobe Flash project with a document class that extends MovieClip: For example Message.as. This class will export an swf call message.swf
    3. Put your loader function in Main.as.
    4. Your message class should written like this:

      public class Message
      {
          private var _msg:String = "";
      
          //Constructor
          public function Message(msg:String)
          {
              _msg = msg;
          }
      
          //Getter method
          public function get msg():String
          {
              return _msg;
          }
      }
      
    5. In Main.as write loader function as you done and load message.swf (pay attention to file system position).

    6. When load is complete you can call getter method msg directly on loaded swf:

      function onLoad(evt:Event):void
        {
         var loadedM:MovieClip = LoaderInfo(evt.target).content as MovieClip; 
         trace(loadedM.msg);
        }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.