Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

actionscript 3 - as3 Main-Timline calling a function from a class loaded from Child.swf

UPDATE: OK I am about ready to give up on Pacakages and classes. No answers coming. Not sure what to do. I tried to make the question easier and made a new post but I was down voted for it. as3 calling a function in another class


I am TOTALLY NEW to using PACKAGES and CLASSES. I am finally converting over from the timeline after having so many issues. Please be patient with my lack of knowledge. I need to know how to call a function in the child swf file I loaded from code in the maintime in the parent swf.

There are 2 swf files. Main.swf and pConent.swf 1. Main.swf has code in the timeline of the first frame. 2. pConent.swf is loading a PACKAGE CLASS as file.

QUESTIONS I am trying to call a function in it from its parent Main.swf. How do I do this? Here is sections of the code from both. Thanks

Main.swf CODE /// is an AIR for Andrid swf

function LoadContent()
{  
    TheContent.load(new URLRequest( "pContent.swf"));
    TheContent.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadContentTWO);
    function LoadContentTWO(e:Event)
    {
        Content = TheContent.content as MovieClip;
        pContent = Content as Object;
        addChild(TheContent);

            var OSS:String = "device";
            trace(pContent); //// comes out as: [object pContent]
        pContent.GetOnlineStatus(OSS); ///// HOW DO I GET THIS TO CALL FUNCTION
    } 
}

A SECTION OF THE "CLASS" in pContent.swf I am trying to call

 public function GetOnlineStatus(OS:String)

{

    if(OS=="online")
        trace("inside ONLINE" );
        }
    if(OS=="device")
        {
        trace("inside DEVICE" );
        }
}

THE ERROR I AM GETTING

TypeError: Error #1006: GetOnlineStatus is not a function.

UPDATE: I decided to post the FULL PACKAGE ( my first) to see if I am doing it right.

package  
{

import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.*;
import flash.media.Sound;
import flash.system.*;
import flash.media.SoundChannel;
import flash.display.MovieClip;
import flash.events.MouseEvent;




    public class pContent extends MovieClip 
    { 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

var ScreenY = flash.system.Capabilities.screenResolutionY;
var ScreenX = flash.system.Capabilities.screenResolutionX;
var swf:String;
var daSounds:String;
var images:String;
var videos:String;
var OnlineStatus:Boolean;



//++++++++++++++++++++++++
//++++++++++++++++++++++++

public function pContent()
    {
    BG.addEventListener(MouseEvent.CLICK, mouseHandlerdown);        
    }

//++++++++++++++++++++++++
//++++++++++++++++++++++++





    //-------- * FUNCTIONS * --------
    //-------------------------------

    public function mouseHandlerdown(event:MouseEvent):void 

        {
        alpha = .3; // testing
        }

    public function GetOnlineStatus(OS:String)
        {

        if(OS=="online")
            {
            OnlineStatus = true;
            Security.allowDomain("*");
            trace("inside THE PATH " + ThePath.text);
            daSounds = "http://mycontactcorner.com/upload/files/";
            swf =    "http://mycontactcorner.com/upload/files/";
            trace("inside THE DEVICE ONLINE" );
            OnlineStatus = false;
            swf = "";
            daSounds = "content/sounds/";
            //LoadMenu();
            LoadStage();
            LoadBeau();
            }
        if(OS=="device")
            {
            trace("inside THE DEVICE ONLINE" );

            }
        }

    //------ * END FUNCTIONS * -----            
    //------------------------------ 



    }// END FUNCTION pContent
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



}//// END PACKAGE
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Don't be disappointed, but I won't have a "real" answer to your question, and I am really not going to work through all of your code to solve it, either. It is your own task to learn how to do this, and unless people here are very, very hungry for reputation, no one will do it for you - we will only help you to find the right way.

Your problem is not "packages and classes", so please do not give up on them. They will help you a great deal, once you've started to understand them. Your problem is, that you are not facing a single problem, but actually at least two (and quite substantial ones, I might add):

  1. You need to go back to learn about the basics of object oriented programming in ActionScript. You won't have much luck getting answers to questions like this, otherwise. And believe me, I don't mean that in a patronizing way - it is simply a complicated matter, and it is hard to communicate complicated issues, both when you don't know the terms to express them, or when your counterpart doesn't understand them. Think of it like a high school math problem: You won't ever find a solution to your trigonometry question (or get a decent answer), unless you learn some basic algebra first.

  2. You also have a problem related to loading, application domains, and the Flash Player security model - which are all far more complicated than what you should aim at when trying out OOP stuff. This can be a major obstacle, and unless you want to frustrate yourself, you should try to avoid it, until your program actually runs.

So this here is my advice: Always try to solve one problem at a time. Do not work yourself into such complex scenarios as the one you are in right now, but take step by step, until you've reached a level where you are confident with what you are doing.

Your first issue should be to understand what's going on with classes and objects. Everything else will come later. You should try to isolate your problem in the pContent.swf and get that to work first - or better yet, put everything you need for your program into a single file. Convert to using classes. Then, once you know how to work with those, start learning about more advanced OO, decoupling your code using interfaces, type casting and loading binaries at runtime.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...