Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 根据定义(数组)更改图像_Image_Actionscript 3_Dictionary - Fatal编程技术网

Image 根据定义(数组)更改图像

Image 根据定义(数组)更改图像,image,actionscript-3,dictionary,Image,Actionscript 3,Dictionary,我正在做一本又小又有趣的字典 到目前为止,我有一个搜索栏。当用户输入一个单词时,他得到了定义。 我想知道是否有可能将图像与定义相关联 这是我的密码: public class Main extends Sprite{ private var ac:AutoComplete; private var conteneurImage:Loader = new Loader(); private var image:URLRequest = new UR

我正在做一本又小又有趣的字典

到目前为止,我有一个搜索栏。当用户输入一个单词时,他得到了定义。 我想知道是否有可能将图像与定义相关联

这是我的密码:

public class Main extends Sprite{

        private var ac:AutoComplete;
        private var conteneurImage:Loader = new Loader();
        private var image:URLRequest = new URLRequest("images/tannoy.gif");
        conteneurImage.load(image);
        private var fruitArray:Array = [
        {label:"A bloc", Type:"Très fort", Description:"une boîte de achards"}, 
        {label:"A fond", Type:"vie", Description:"Loulou"}, 
        {label:"dfgdf", Type:"à grande vitesse.", Description:"Indique une vitesse"}, 
        private var bg:Sprite;
        // A couple of TextFields
        private var t1:TextField;
        private var t2:TextField;
        // An input TextField to show our search results
        private var it1:TextField;
        // A couple of TextFormats
        private var titleFormat:TextFormat;
        private var titleFormatW:TextFormat;
        // Two variables to hold our x and y positions
        private var xPos:int;
        private var yPos:int;


// Whenever we need to see the List component which is part of the AutoComplete class, an event is dispatched by the AutoComplete class and is picked up in the ListDepth function
        // This takes our instance of the AutoComplete class - ac - and moves it to the highest available depth, which is the numChildren ( all the elements on stage ) - 1.
        private function listDepth(e:Event):void{
            setChildIndex(ac, numChildren - 1);
        }

        // This function is also a response to an event dispatched from the AutoComplete class. It takes the results, or lack of them, and displays that information in our it1 TextField
        private function setDisplay(e:Event):void{
            var fIndex:int = ac.aIndex;
            if(fIndex == -1){
                it1.text = ac.noResult;
                it1.setTextFormat(titleFormat);
            }else{
                it1.htmlText = "<b>Définition rapide :</b> " + fruitArray[fIndex].Type + "<br/><br/><b>Définition complète:</b> " + fruitArray[fIndex].Description;
                it1.setTextFormat(titleFormat);
            }
        }
public类主扩展Sprite{
私有变量ac:自动完成;
private var contenneurimage:Loader=new Loader();
private-var-image:URLRequest=new-URLRequest(“images/tannoy.gif”);
加载(图像);
私有变量数组:数组=[
{标签:“一个集团”,类型:“托雷斯堡”,描述:“乌内博特·德·阿查德”},
{标签:“喜欢”,类型:“vie”,描述:“Loulou”},
{标签:“dfgdf”,类型:“A grande vitesse.”,描述:“Indique une vitesse”},
私有变量bg:Sprite;
//几个文本字段
私有变量t1:TextField;
私有变量t2:TextField;
//显示搜索结果的输入文本字段
私有变量it1:TextField;
//两种文本格式
私有变量标题格式:TextFormat;
私有变量titleFormatW:TextFormat;
//保持x和y位置的两个变量
私有变量xPos:int;
私有变量yPos:int;
//每当我们需要查看作为AutoComplete类一部分的List组件时,AutoComplete类就会发送一个事件,并在ListDepth函数中拾取该事件
//这将使用我们的AutoComplete类-ac-的实例,并将其移动到可用的最高深度,即numChildren(舞台上的所有元素)-1。
私有函数listDepth(e:事件):void{
setChildIndex(ac,numChildren-1);
}
//此函数也是对从AutoComplete类调度的事件的响应。它获取结果,或者没有结果,并在it1文本字段中显示该信息
私有函数setDisplay(e:事件):无效{
var fIndex:int=ac.aIndex;
如果(fIndex==-1){
it1.text=ac.noResult;
it1.setTextFormat(标题格式);
}否则{
it1.htmlText=“定义速度:”+fruutarray[fIndex]。键入+”

Définition complète:“+fruutarray[fIndex]。说明; it1.setTextFormat(标题格式); } }
那么,你认为有可能把图像和标签联系起来吗

差不多

 <img src="smiley.gif">

或者

it1.htmlText = "<b>Définition rapide :</b> " + fruitArray[fIndex].Type + "<br/><br/><b>Définition complète:</b> " + fruitArray[fIndex].Description;
it1.htmlText=“Définition rapide:“+fruitArray[fIndex]。键入+”

Définition complète:“+fruitArray[fIndex]。说明;
可能会添加一个代码,告诉您在这行中搜索图像

你觉得我怎么能做到


Thx

我推荐两种选择:

1) 创建一个类单词(或任何其他有意义的名称)。在此类中,如果需要,为单词本身或名称数组创建一个变量。还为图像和任何其他要保留的数据添加一个变量

下面是一个例子:

package  {

    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.display.DisplayObject;


    public class Word
    {

        public var en_name:String;
        public var fr_name:String;

        public var image:DisplayObject;
        public var imageURL:String;

        private var imageLoader:Loader;

        public function loadImage():void
        {
            imageLoader = new Loader();
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
            imageLoader.load(new URLRequest(imageURL));
        }

        private function onImageLoaded(e:Event):void
        {
            imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onImageLoaded);
            image = imageLoader.content;
            imageLoader = null;
        }
    }

}
现在不再使用字符串数组,而是使用单词数组。您可以使用不同的语言和图像访问它们的名称。如果您想从外部加载图像,我甚至还提供了一个加载程序(或者您可以直接分配图像变量).对于字典来说,这不是最具扩展性的版本,但您可以根据自己的需要自由扩展和改进它

2) 稍微不那么优雅,-只需创建字符串和图像数组。当您访问名称数组时,如fruitArray[4],您也可以使用相同的访问点访问图像数组,如fruitPictureArray[4]

希望有帮助