EventListner

Hello

My requirement is not to import the .docx files, if a user importing .docx, then the script need to alert for further confirmation.

My idea is using the event listener and put the script in the startup scripts folder. Here is the code I tried:

#targetengine "session"
main();
function main(){
var myEventListener = app.addEventListener("beforePlace", myPlaceFile, false);
}
function myPlaceFile(myEvent){
var myconfirm=confirm("You are placing docx file? Shall continue?")
if(myconfirm)
{
// here need to place the files
}
else{
//need to exit

}

}

Kind regards

Kitty

Hello Kitty,

I think that almost everyone is a "beginner" when it comes to event listeners.

You have to do a lot of testing to anticipate what is happening where and when.

I can give you the following code, which is not "field test".

For example I have not test what will happen, if the user is dragging more than one file for the document (is this possible at all?)

There may be circumstances where the code does not work as expected or bored the user too.

It is also questionable how much we like to intercept the import or investment process.
In any case, to do with "beforeImport" or "afterImport". Otherwise, the name of the file cannot be found (at least to my knowledge).

It might be, that there are also "beforePlace" and "afterPlace" for some controls or to control the process more densely. Also inspect the placeGun may be necessary perhaps.

Before the test, read my comments in the script, there is room for improvement.
Test also with other suffixes of file as "txt".

// Notify-and-UndoPlacingOf-WordFiles-COMMENTED-VERSION.jsx
// Uwe Laubender

/**
* @@@BUILDINFO@@@ Notify-and-UndoPlacingOf-WordFiles-COMMENTED-VERSION.jsx !Version! Tue Jan 19 2016 07:06:06 GMT+0100
*/

// See discussion at:
// https://forums.adobe.com/message/8399607#8399607

// NOTE:
// I did not test this, just a suggestion:
// ONE VARIANT COULD BE NOT TO USE THE "afterSelectionChanged" EVENT LISTENER FROM THE START,
// BUT TO ADD IT AFTER THE USER CANCELS IT, HAVE THE TWO undo() AND REMOVE IT AFTER DOING THIS.
// "afterSelectionChanged" IS VERY OFTEN FIRED, SO IT WOULD BE GOOD TO MINIMIZE ITS USE.

#targetengine "Notify-and-UndoPlacingOf-WordFiles"

// FLAG, THAT IS SET, IF THE USERS CONFIRMS, THAT HE/SHE DOES NOT LIKE TO IMPORT doc/docx FILES:
// Default value is: false
var undoPlaceWordFile = false;

// Variable is not used further in this script snippet.
var myBeforeImport = app.eventListeners.add("beforeImport",checkAllowImport);
// Variable is not used further in this script snippet.
var myAfterSelectionChanged = app.eventListeners.add("afterSelectionChanged",undoPlaceIfPlacedAWordFile);

// Purpose of this function:
// 1. Check, how flag is set:

// false : do nothing
// true : do two undo() actions

// 2. Afterwards reset the flag to default

function undoPlaceIfPlacedAWordFile(myAfterSelectionChangedEvent)
{
    if(undoPlaceWordFile === false){return};

    // That would load the place gun again or undo a replacement action:
    app.documents[0].undo();
    // That would undo importing the file:
    app.documents[0].undo();

    // Note 1: Even, if this will work,
    // the user could load the place gun when he/she will undo the undo.

    // Note 2: Before doing every undo(), you can check the value of:
    // document.undoName
    // to determine, if the undo() should be done.

    // Reset the flag to default:
    undoPlaceWordFile = false;
}

// Purpose of this function:
// Check the file name of the imported file and decide, if it is a Word document.
// I do this with a match on the string of the file name. The suffixes doc and docx at the end of the name.
// If there is no suffix or the suffix will not match, the function will do nothing.

function checkAllowImport(myBeforeImportEvent)
{

    var myPlacedFile = File(myBeforeImportEvent.fullName);

    // If files are about to be placed, that do NOT MATCH file suffixes ".doc" or ".docx", the function will do nothing.
    // Or if the file has no suffix at all.

    // This matching procedure could be refined perhaps looking into the file.

    if(!myPlacedFile.name.match(/(\.doc$)|(\.docx$)/i)){return};

    // If the show goes on, a confirm dialog will be started, that will set the undoPlaceWordFile flag

    // myConfirm : true  does mean the user likes to place the doc file, do nothing then.

    // myConfirm : false does mean the user likes to undo() the import.
    // The flag will be set to value true.
    // The doc or docx file will be placed.
    // That will force a afterSelectionChanged event (see function undoPlaceIfPlacedAWordFile() above),
    // either a new frame is created and selected
    // or a selected text will be changed (replaced) after placing.

    var myConfirm = confirm("You are about to place a Word file. Shall we continue?");

    // Do nothing:
    if(myConfirm === true){return};

    // Reset the flag to value true; no if-clause really needed here, just to show you the mechanism better:
    if(myConfirm === false){undoPlaceWordFile = true};

};

Sorry, I will no more give a writing help and test it. Too much time goes into this.

But I think that you can get the ideas behind it now. Do a lot of tests, also with some statements of $. writeln() to get the idea of what are the listeners and the properties and values you can check by listening to something.

Uwe

Tags: InDesign

Similar Questions

  • Delete / external swf or the files in the flash file main to unload and load a new swf file and memory garbage collection.

    I can't delete / unload the example swf files external when the carousel.swf (portfolio) appears and press the button about the content overlaps the carousel (portfolio). How can I delete / unload an external swf file in the main flash file and load a SWF, so that at the same time remove garbage collection memory operation?

    This is the error messages I receive: "TypeError: Error #2007: child parameter must be non null.»

    at flash.display::DisplayObjectContainer/removeChild()

    " to index_fla::MainTimeline/Down3().

    Import nl.demonsters.debugger.MonsterDebugger;

    var d: MonsterDebugger = new MonsterDebugger (this);

    stage.scaleMode = StageScaleMode.NO_SCALE;

    internship. Align = StageAlign.TOP_LEFT;

    stage.addEventListener (Event.RESIZE, resizeHandler);

    is the charger for the portfolio page swf

    var loader: Loader;

    var loader2:Loader;

    var loader3:Loader;

    var loader1:Loader;

    resize the content

    function resizeHandler(event:Event):void {}

    resizes the portfolio page to Center

    Loader.x = (stage.stageWidth - loader.width) *. 5;

    Loader.y = (stage.stageHeight - loader.height) *. 5;

    resizes on page to Center

    loader3.x = (stage.stageWidth - 482) *.5 - 260;

    loader3.y = (stage.stageHeight - 492) *.5 - 140;

    * loader2.x = (stage.stageWidth - 658.65) *. 5;

    loader2.y = (stage.stageHeight - 551.45) *. 5; * /

    }

    addEventListener (Event.ENTER_FRAME, onEnterFrame, false, 0, true);

    function onEnterFrame(ev:Event):void {}

    var requesterb:URLRequest = new URLRequest ("carouselLoader.swf");

    Charger = null;

    loader = new Loader();

    Loader.Name = "carousel1.

    Adds gallery.swf in the scene at the beginning of the film

    loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioError);

    function ioError(event:IOErrorEvent):void {}

    trace (Event);

    }

    try {}

    Loader.Load (requesterb);

    } catch (SecurityError: error) {}

    trace (Error);

    }

    addChild (loader);

    Loader.x = (stage.stageWidth - 739) *. 5;

    Loader.y = (stage.stageHeight - 500) *. 5;

    stopover gallery.swf duplication and more on enter frame

    removeEventListener (Event.ENTER_FRAME, onEnterFrame);

    }

    PORTFOLIO BUTTON

    Add eventlistner so that gallery.swf can be loaded

    MovieClip (root),.nav.portfolio.addEventListener (MouseEvent.MOUSE_DOWN, down, false, 0, true);

    function Down(event:MouseEvent):void {}

    Re add listener for contact.swf and about.swf

    MovieClip (root).nav.info.addEventListener (MouseEvent.MOUSE_DOWN, Down1, false, 0, true);

    MovieClip (root).nav.about.addEventListener (MouseEvent.MOUSE_DOWN, Down3, false, 0, true);

    discharge of entry gallery.swf frame if users press portfolio in nav button

    var applicant: URLRequest = new URLRequest ("carouselLoader.swf");

    Charger = null;

    loader = new Loader();

    Loader.Name = "carousel."

    loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioError);

    function ioError(event:IOErrorEvent):void {}

    trace (Event);

    }

    try {}

    Loader.Load (requester);

    } catch (SecurityError: error) {}

    trace (Error);

    }

    addChild (loader);

    Loader.x = (stage.stageWidth - 739) *. 5;

    Loader.y = (stage.stageHeight - 500) *. 5;

    removeChild (getChildByName ("about"));

    removeChild (getChildByName ("carousel1"));

    delete eventlistner and prevents duplication of the gallery.swf

    MovieClip (root).nav.portfolio.removeEventListener (MouseEvent.MOUSE_DOWN, down);

    }

    INFORMATION BUTTON

    Add eventlistner so that info.swf can be loaded

    MovieClip (root).nav.info.addEventListener (MouseEvent.MOUSE_DOWN, Down1, false, 0, true);

    function Down1(event:MouseEvent):void {}

    This adds the EventListener for portfolio so that the end user can re-post if they wish.

    MovieClip (root),.nav.portfolio.addEventListener (MouseEvent.MOUSE_DOWN, down, false, 0, true);

    MovieClip (root).nav.about.addEventListener (MouseEvent.MOUSE_DOWN, Down3, false, 0, true);

    var applicant: URLRequest = new URLRequest ("contactLoader.swf");

    loader2 = null;

    loader2 = new Loader();

    loader2. Name = "contact".

    loader2.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioError);

    function ioError(event:IOErrorEvent):void {}

    trace (Event);

    }

    try {}

    loader2. Load (requester);

    } catch (SecurityError: error) {}

    trace (Error);

    }

    addChild (loader2);

    loader2.x = (stage.stageWidth - 658.65) *. 5;

    loader2.y = (stage.stageHeight - 551.45) *. 5;

    delete eventlistner and prevents duplication of the info.swf

    MovieClip (root).nav.info.removeEventListener (MouseEvent.MOUSE_DOWN, Down1);

    }

    ON THE BUTTON

    Add eventlistner so that info.swf can be loaded

    MovieClip (root).nav.about.addEventListener (MouseEvent.MOUSE_DOWN, Down3, false, 0, true);

    function Down3(event:MouseEvent):void {}

    This adds the EventListener for portfolio so that the end user can re-post if they wish.

    MovieClip (root),.nav.portfolio.addEventListener (MouseEvent.MOUSE_DOWN, down, false, 0, true);

    MovieClip (root).nav.info.addEventListener (MouseEvent.MOUSE_DOWN, Down1, false, 0, true);

    var applicant: URLRequest = new URLRequest ("aboutLoader.swf");

    loader3 = null;

    loader3 = new Loader();

    loader3. Name = "a connection"

    loader3.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioError);

    function ioError(event:IOErrorEvent):void {}

    trace (Event);

    }

    try {}

    loader3. Load (requester);

    } catch (SecurityError: error) {}

    trace (Error);

    }

    addChild (loader3);

    loader3.x = (stage.stageWidth - 482) *.5 - 260;

    loader3.y = (stage.stageHeight - 492) *.5 - 140;

    removeChild (getChildByName ("carousel"));

    removeChild (getChildByName ("carousel1"));

    delete eventlistner and prevents duplication of the info.swf

    MovieClip (root).nav.about.removeEventListener (MouseEvent.MOUSE_DOWN, Down3);

    }

    Stop();

    You call unload() on objects that you cancelled - where the error.

    You should do something like:

    {if (loader2)}

    loader2. Unload();

    }

    As for the null value passed into the function - null is a default value. In this way, you can call the low past nothing:

    Down()

    Or you can use it as a handler in which case it will be called by the Auditor:

    Down (mouseEventInstnace);

  • call a function in the hull of the SWF to a SWF imported

    We have set flash up as a shell to retrieve data from the lesson in XML and display image by image.

    We import SWF files when the XML code that tells it to affix the frame.

    How can I get the SWF file imported to call a function in the hull...

    basically a button or movie clip in swf call imported the function "gotoNextFrame()" in the hull.

    We found an easier way to 'bit' if anyone is interested... We have an eventlistner added to the charger to assign an event in the swf file that is imported:

    flashLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, addEventHandlers);

    then when its done, it adds event listeners and calls our function "goNextFrame" (then it clears when its removed from the scene):

    function addEventHandlers(event:Event):void
    {

    var swfMC:MovieClip = event.target.content as MovieClip;

    swfMC.addEventListener ("NextFrame", goNextFrame);
    swfMC.addEventListener ("PreviousFrame", goPrevFrame);
    swfMC.addEventListener (Event.REMOVED_FROM_STAGE, clearEventListeners);

    }

    Then in the swf file that will be imported, its real simple:

    next_btn.addEventListener (MouseEvent.CLICK, MoveToNextFrame);
    prev_btn.addEventListener (MouseEvent.CLICK, MoveToPreviousFrame);

    function MoveToNextFrame(e:MouseEvent):void
    {
    dispatchEvent (new Event ("NextFrame"));
    }

    function MoveToPreviousFrame(e:MouseEvent):void
    {
    dispatchEvent (new Event ("PreviousFrame"));
    }

Maybe you are looking for

  • Keyboard does not not with IOS 10

    I just downloaded the IOS 10 today, and the keyboard does not appear. I can almost see below the iMessage space where you normally text; However, I can't access it. I can't access my keyboard in Contacts, Notes or any other applications. Help, please

  • FN keys do not work on my Satellite L505

    I use the new Windows 7 and have no programs of Toshiba and cannot open the FN + F8, F9 keys.Why do they work?What should I do? Pls help!Answer pls clearly what I understand!

  • HP Mini 2102: Exchange hard drive on HP Minis (2102/110-1025DX)

    I have two HP Minis; 2102 and 110-1025DX. Both are running Windows 10 Pro and were responsible for similar programs. For several reasons, I want to be able to swap hard drives between these two devices, but I don't know how possible it would be. My q

  • Windows XP Home OS for mp3 player

    I'm about to buy a new Sony mp3 player. Sony, as opposed to Apple, because I want to be able to download files directly from Media Player in my office. The description of the product lists Windows XP Home it's OS. Never mp3 players connect to the web

  • Windows 7 Outlook image domain profile question

    We have a PC Windows 7 64 - bit, Ghost image of the PC, but when the first user opens a session, outlook goes into their profile, when the user opens a next session in it goes to the first users profile that connects.  There is no prompt that appears