AS3主Timline呼吁从Child.swf装载的类中的函数 [英] as3 Main-Timline calling a function from a class loaded from Child.swf

查看:207
本文介绍了AS3主Timline呼吁从Child.swf装载的类中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:好,我正要准备放弃Pacakages和类。没有答案来了。不知道该怎么做。我试图使这个问题更加容易,并提出了新的职位,但我下来投了赞成票。 AS3在另一个类调用一个函数


我是全新的使用包和类。我终于转换了从时间线上有这么多的问题之后。请耐心等待我的知识的缺乏。我需要知道如何调用在我的code装在父SWF的maintime子SWF文​​件中的函数。

有2 SWF文件。的main.swf和pConent.swf  1. main.swf中有code中的第一帧的时间轴。  2. pConent.swf加载一个软件包类的文件。

问题 我试图从母公司的main.swf调用一个函数在里面。我该怎么做呢? 下面是从两个code部分。谢谢

的main.swf code ///是AIR的Andr​​id SWF

 函数LoadContent()
{
    TheContent.load(新的URLRequest(pContent.swf));
    TheContent.contentLoaderInfo.addEventListener(引发Event.COMPLETE,LoadContentTWO);
    功能LoadContentTWO(五:事件)
    {
        内容= TheContent.content为影片剪辑;
        pContent =内容对象;
        的addChild(TheContent);

            VAR OSS:字符串=设备;
            跟踪(pContent); ////出来为:对象pContent]
        pContent.GetOnlineStatus(OSS); /////如何我得到这个通话功能
    }
}
 

在pContent.swf类我想调用的栏目

 公共职能GetOnlineStatus(OS:字符串)

{

    如果(OS ==在线)
        跟踪(里ONLINE);
        }
    如果(OS ==设备)
        {
        跟踪(内部设备);
        }
}
 

的错误我收到

类型错误:错误#1006:GetOnlineStatus不是一个函数

更新:我决定发布完整的包(我的第一个),看看如果我这样做是正确

 包
{

进口的flash.display.MovieClip;
进口fl.transitions.Tween;
进口fl.transitions.easing中*。
进口fl.transitions.TweenEvent;
导入flash.display使用*。
进口flash.media.Sound;
进口flash.system通过*。
进口flash.media.SoundChannel;
进口的flash.display.MovieClip;
进口flash.events.MouseEvent;




    公共类pContent扩展影片剪辑
    {
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

VAR ScreenY = flash.system.Capabilities.screenResolutionY;
VAR ScreenX = flash.system.Capabilities.screenResolutionX;
VAR SWF:字符串;
VAR daSounds:字符串;
VAR图片:字符串;
VAR视频:字符串;
VAR OnlineStatus:布尔;



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

公共职能pContent()
    {
    BG.addEventListener(MouseEvent.CLICK,mouseHandlerdown);
    }

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





    // -------- *功能* --------
    // -------------------------------

    公共职能mouseHandlerdown(事件:MouseEvent)方法:无效

        {
        阿尔法= 0.3; //测试
        }

    公共职能GetOnlineStatus(OS:字符串)
        {

        如果(OS ==在线)
            {
            OnlineStatus = TRUE;
            的Security.allowDomain(*​​);
            跟踪(里面的PATH+ ThePath.text);
            daSounds =htt​​p://mycontactcorner.com/upload/files/;
            瑞士法郎=htt​​p://mycontactcorner.com/upload/files/;
            跟踪(设备设置为在线内部);
            OnlineStatus = FALSE;
            瑞士法郎=;
            daSounds =内容/声音/;
            // LoadMenu();
            LoadStage();
            LoadBeau();
            }
        如果(OS ==设备)
            {
            跟踪(设备设置为在线内部);

            }
        }

    // ------ * END功能* -----
    // ------------------------------



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



} //// END PACKAGE
 

解决方案

不要失望,但我不会有一个真实的回答你的问题,我真的不打算工作,通过所有的code来解决它,无论是。这是你自己的任务,以了解如何做到这一点,除非这里的人都非常渴望名声,没有人会为你做它 - 我们只会帮你找到正确的方式

您的问题不是包和类,所以请不要放弃他们。他们会帮你很大的,一旦你开始了解他们。你的问题是,你是不是面临着一个问题,但实际上至少有两个(和相当可观的,我可以补充):

  1. 您需要回去了解的基础知识面向对象编程在ActionScript 。你不会有太多运气得到答案,这样的问题,否则。相信我,我的意思不是说在一个光顾的方式 - 那简直是一件复杂的事情,这是很难沟通复杂的问题,无论是当你不知道该条款前preSS它们,或者当你的对手不理解他们。你可以把它像一个高中的数学题:你永远不会找到一个解决方案,以你的三角问题(或者得到一个体面的答案),除非你先学会一些基本的代数。

  2. 您也有相关的加载,应用领域中的问题 Flash Player安全模型 - 这些都是更为复杂的比你的目标应该是尝试面向对象的东西的时候。这可能是一个主要的障碍,除非你想阻挠你自己,你应该尝试的避免它,直到你的程序实际运行的。

所以这这里是我的建议是:始终试图解决一个问题的时间。不要工作自己陷入这种复杂的情况下对视了一眼,你是在现在,而是采取分步实施,直到你达到你有信心与你在做什么的程度。

您的第一个问题应该是明白什么用类和对象的事情。所有其他的事情以后还会来。你应该尝试找出你的问题在​​ pContent.swf 并获得第一工作 - 或者更好的是,把你需要为你的程序到一个文件中的一切。转换为使用类。然后,一旦你知道如何与这些工作,开始学习更先进的面向对象,的使用去耦的code接口的,<一个href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f87.html"相对=nofollow>类型转换和的加载二进制文件在运行时

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

解决方案

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.

这篇关于AS3主Timline呼吁从Child.swf装载的类中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆